#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 */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
size_t strlen(char *);
char toupper(char);
char *strupr(char *str) {
  size_t len;
  size_t i;
  assert(str != NULL);
  len = strlen(str);
  for (i = 0; i < len; ++i)
    str[i] = toupper(str[i]);
  return str;
}


x86 assembly (clang, -O0):
<strupr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a0 <strupr+0x70>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1163 <strupr+0x33>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strupr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1050 <assert@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %rax,%rax
je     1177 <strupr+0x47>
mov    %rax,%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <strupr+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strupr(i8* returned %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %14, label %7
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 i64 %8, 1
%13 = icmp eq i64 %12, %5
br i1 %13, label %14, label %7
14: ; preds = %7, %1
ret i8* %0
}