#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 */
size_t strlen(char *);
char toupper(char);
void strtoupper(char *str) {
  size_t i;
  for (i = 0; i < strlen(str); ++i)
    str[i] = toupper(str[i]);
}


x86 assembly (clang, -O0):
<strtoupper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
jae    1184 <strtoupper+0x64>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <strtoupper+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoupper>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     116f <strtoupper+0x4f>
mov    %rdi,%r14
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%r14)
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%rax
jb     116f <strtoupper+0x4f>
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jb     1150 <strtoupper+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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