#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 */
scalar_t__ strlen(char *);
char toupper(char);
void string_to_upcase(char *string) {
  int i;
  if (strlen(string) > 0) {
    for (i = 0; i < (int)strlen(string); i++) {
      string[i] = toupper(string[i]);
    };
  };
  return;
}


x86 assembly (clang, -O0):
<string_to_upcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    1194 <string_to_upcase+0x74>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jge    118f <string_to_upcase+0x6f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <string_to_upcase+0x26>
jmp    1194 <string_to_upcase+0x74>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_upcase>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %rax,%rax
jle    1161 <string_to_upcase+0x41>
test   %eax,%eax
jle    1161 <string_to_upcase+0x41>
xor    %ebx,%ebx
nopw   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>
cltq
cmp    %rax,%rbx
jl     1140 <string_to_upcase+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @string_to_upcase(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strlen(i8* %4)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %29
7: ; preds = %1
store i32 0, i32* %3
br label %8
8: ; preds = %25, %7
%9 = load i32, i32* %3
%10 = load i8*, i8** %2
%11 = call i64 @strlen(i8* %10)
%12 = trunc i64 %11 to i32
%13 = icmp slt i32 %9, %12
br i1 %13, label %14, label %28
14: ; preds = %8
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext 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* %3
%23 = sext 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* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %8
28: ; preds = %8
br label %29
29: ; preds = %28, %1
ret void
}

LLVM IR (-O2):
define void @string_to_upcase(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp sgt i64 %2, 0
%4 = trunc i64 %2 to i32
%5 = icmp sgt i32 %4, 0
%6 = and i1 %3, %5
br i1 %6, label %7, label %17
7: ; preds = %1, %7
%8 = phi i64 [ %12, %7 ], [ 0, %1 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call signext i8 @toupper(i8 signext %10)
store i8 %11, i8* %9
%12 = add nuw nsw i64 %8, 1
%13 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%14 = shl i64 %13, 32
%15 = ashr exact i64 %14, 32
%16 = icmp slt i64 %12, %15
br i1 %16, label %7, label %17
17: ; preds = %7, %1
ret void
}