#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 toupper(char const);
const char *str_to_upper(const char *str) {
  static char buf[1024];
  char *p;
  int i = 0;
  for (p = buf; *str && i < 1023; str++, p++, i++)
    *p = toupper(*str);
  *p = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<str_to_upper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0x2f16(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x15(%rbp)
je     1150 <str_to_upper+0x40>
cmpl   $0x3ff,-0x14(%rbp)
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1160 <str_to_upper+0x50>
jmp    119a <str_to_upper+0x8a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112e <str_to_upper+0x1e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e98(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_upper>:
push   %r15
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     115a <str_to_upper+0x4a>
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0x2f19(%rip),%r15
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%rbx,%r15,1)
movzbl 0x1(%r14,%rbx,1),%eax
lea    0x1(%rbx),%rcx
test   %al,%al
je     1155 <str_to_upper+0x45>
cmp    $0x3fe,%ebx
mov    %rcx,%rbx
jb     1130 <str_to_upper+0x20>
add    %rcx,%r15
jmp    1161 <str_to_upper+0x51>
lea    0x2edf(%rip),%r15
movb   $0x0,(%r15)
lea    0x2ed4(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@str_to_upper.buf = internal global [1024 x i8] zeroinitializer
define i8* @str_to_upper(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_to_upper.buf, i64 0, i64 0), i8** %3
br label %5
5: ; preds = %20, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 1023
br label %13
13: ; preds = %10, %5
%14 = phi i1 [ false, %5 ], [ %12, %10 ]
br i1 %14, label %15, label %27
15: ; preds = %13
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = call signext i8 @toupper(i8 signext %17)
%19 = load i8*, i8** %3
store i8 %18, i8* %19
br label %20
20: ; preds = %15
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %2
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %5
27: ; preds = %13
%28 = load i8*, i8** %3
store i8 0, i8* %28
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_to_upper.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@str_to_upper.buf = internal global [1024 x i8] zeroinitializer
define i8* @str_to_upper(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %13, %4 ], [ %2, %1 ]
%6 = phi i32 [ %12, %4 ], [ 0, %1 ]
%7 = phi i8* [ %11, %4 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_to_upper.buf, i64 0, i64 0), %1 ]
%8 = phi i8* [ %10, %4 ], [ %0, %1 ]
%9 = tail call signext i8 @toupper(i8 signext %5)
store i8 %9, i8* %7
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = add nuw nsw i32 %6, 1
%13 = load i8, i8* %10
%14 = icmp ne i8 %13, 0
%15 = icmp ult i32 %6, 1022
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %4, label %17
17: ; preds = %4, %1
%18 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_to_upper.buf, i64 0, i64 0), %1 ], [ %11, %4 ]
store i8 0, i8* %18
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @str_to_upper.buf, i64 0, i64 0)
}