#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 */
unsigned int strlen(char *);
char toupper(char);
void str_uppercase(char *sequence) {
  unsigned int l, i;
  if (sequence) {
    l = strlen(sequence);
    for (i = 0; i < l; i++)
      sequence[i] = toupper(sequence[i]);
  }
}


x86 assembly (clang, -O0):
<str_uppercase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1185 <str_uppercase+0x65>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1180 <str_uppercase+0x60>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114a <str_uppercase+0x2a>
jmp    1185 <str_uppercase+0x65>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_uppercase>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1157 <str_uppercase+0x37>
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %eax,%eax
je     1157 <str_uppercase+0x37>
mov    %eax,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <str_uppercase+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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