#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 const *);
char toupper(char);
char *_cdio_strdup_upper(const char str[]) {
  char *new_str = ((void *)0);
  if (str) {
    char *p;
    p = new_str = strdup(str);
    while (*p) {
      *p = toupper(*p);
      p++;
    }
  }
  return new_str;
}


x86 assembly (clang, -O0):
<_cdio_strdup_upper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1187 <_cdio_strdup_upper+0x67>
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1182 <_cdio_strdup_upper+0x62>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1150 <_cdio_strdup_upper+0x30>
jmp    1187 <_cdio_strdup_upper+0x67>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_cdio_strdup_upper>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1158 <_cdio_strdup_upper+0x38>
call   1040 <strdup@plt>
mov    %rax,%r14
mov    (%rax),%al
test   %al,%al
je     115b <_cdio_strdup_upper+0x3b>
mov    %r14,%rbx
add    $0x1,%rbx
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <_cdio_strdup_upper+0x20>
jmp    115b <_cdio_strdup_upper+0x3b>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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