#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 toupper(char);
void str_toupper(char *str) {
  char *p = str;
  while (*p != '\0') {
    *p = islower(*p) ? toupper(*p) : *p;
    p++;
  }
}


x86 assembly (clang, -O0):
<str_toupper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1197 <str_toupper+0x77>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     1171 <str_toupper+0x51>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <str_toupper+0x5b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <str_toupper+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_toupper>:
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     115b <str_toupper+0x3b>
mov    %rdi,%rbx
jmp    113e <str_toupper+0x1e>
nopl   0x0(%rax)
mov    %al,(%rbx)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     115b <str_toupper+0x3b>
movsbl %al,%edi
call   1030 <islower@plt>
mov    %rax,%rcx
movzbl (%rbx),%eax
test   %rcx,%rcx
je     1130 <str_toupper+0x10>
movsbl %al,%edi
call   1040 <toupper@plt>
jmp    1130 <str_toupper+0x10>
pop    %rbx
ret

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

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