#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__ islower(char);
char *strdup(char *);
int strlen(char *);
char toupper(char);
char *str_toupper(char *fr) {
  char *rval;
  int i;
  rval = strdup(fr);
  for (i = 0; i < strlen(rval); i++) {
    if (islower(rval[i]))
      rval[i] = toupper(rval[i]);
  }
  return rval;
}


x86 assembly (clang, -O0):
<str_toupper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11c8 <str_toupper+0x88>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     11b5 <str_toupper+0x75>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ba <str_toupper+0x7a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <str_toupper+0x20>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_toupper>:
push   %r14
push   %rbx
push   %rax
call   1060 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1192 <str_toupper+0x52>
xor    %ebx,%ebx
jmp    1173 <str_toupper+0x33>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1192 <str_toupper+0x52>
movsbl (%r14,%rbx,1),%edi
call   1030 <islower@plt>
test   %rax,%rax
je     1160 <str_toupper+0x20>
movsbl (%r14,%rbx,1),%edi
call   1040 <toupper@plt>
mov    %al,(%r14,%rbx,1)
jmp    1160 <str_toupper+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @str_toupper(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strdup(i8* %5)
store i8* %6, i8** %3
store i32 0, i32* %4
br label %7
7: ; preds = %32, %1
%8 = load i32, i32* %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %35
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = call i64 @islower(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %12
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = call signext i8 @toupper(i8 signext %25)
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
br label %31
31: ; preds = %20, %12
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %7
35: ; preds = %7
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
define i8* @str_toupper(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i32 @strlen(i8* %2)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %1, %14
%6 = phi i64 [ %15, %14 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %2, i64 %6
%8 = load i8, i8* %7
%9 = tail call i64 @islower(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %5
%12 = load i8, i8* %7
%13 = tail call signext i8 @toupper(i8 signext %12)
store i8 %13, i8* %7
br label %14
14: ; preds = %5, %11
%15 = add nuw nsw i64 %6, 1
%16 = tail call i32 @strlen(i8* %2)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %5, label %19
19: ; preds = %14, %1
ret i8* %2
}