#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__ isalpha(char);
char toupper(char);
void strtoupper(char *str) {
  if (!str)
    return;
  while (*str != '\0') {
    if (isalpha(*str))
      *str = toupper(*str);
    str++;
  }
}


x86 assembly (clang, -O0):
<strtoupper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113c <strtoupper+0x1c>
jmp    118c <strtoupper+0x6c>
jmp    1141 <strtoupper+0x21>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118c <strtoupper+0x6c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalpha@plt>
cmp    $0x0,%rax
je     117b <strtoupper+0x5b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1141 <strtoupper+0x21>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoupper>:
push   %rbx
test   %rdi,%rdi
je     1155 <strtoupper+0x35>
mov    %rdi,%rbx
mov    (%rdi),%al
jmp    1138 <strtoupper+0x18>
nopl   (%rax)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1155 <strtoupper+0x35>
movsbl %al,%edi
call   1040 <isalpha@plt>
test   %rax,%rax
je     1130 <strtoupper+0x10>
movsbl (%rbx),%edi
call   1030 <toupper@plt>
mov    %al,(%rbx)
jmp    1130 <strtoupper+0x10>
pop    %rbx
ret

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

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