#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
char *strdup(char *);
int /*<<< orphan*/ toupper(char);
char *strdup_toupper(char *in) {
  char *p, *out;
  p = out = strdup(in);
  if (out)
    do {
      *p++ = toupper(*in);
    } while (*in++);
  return out;
}


x86 assembly (clang, -O0):
<strdup_toupper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1189 <strdup_toupper+0x69>
jmp    114d <strdup_toupper+0x2d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
cmpb   $0x0,(%rax)
jne    114d <strdup_toupper+0x2d>
jmp    1189 <strdup_toupper+0x69>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdup_toupper>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1040 <strdup@plt>
mov    %rax,%r14
test   %rax,%rax
je     1159 <strdup_toupper+0x39>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%r14,%rbx,1)
cmpb   $0x0,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1140 <strdup_toupper+0x20>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strdup_toupper(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strdup(i8* %5)
store i8* %6, i8** %4
store i8* %6, i8** %3
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %23
9: ; preds = %1
br label %10
10: ; preds = %17, %9
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = call i32 @toupper(i8 signext %12)
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
store i8 %14, i8* %15
br label %17
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %2
%20 = load i8, i8* %18
%21 = icmp ne i8 %20, 0
br i1 %21, label %10, label %22
22: ; preds = %17
br label %23
23: ; preds = %22, %1
%24 = load i8*, i8** %4
ret i8* %24
}

LLVM IR (-O2):
define noalias i8* @strdup_toupper(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1, %4
%5 = phi i8* [ %10, %4 ], [ %2, %1 ]
%6 = phi i8* [ %11, %4 ], [ %0, %1 ]
%7 = load i8, i8* %6
%8 = tail call i32 @toupper(i8 signext %7)
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %9, i8* %5
%11 = getelementptr inbounds i8, i8* %6, i64 1
%12 = load i8, i8* %6
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %4, %1
ret i8* %2
}