#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*/ printf(char *, char *);
char *upcase(char *str) {
  char dst;
  char *dp = &dst;
  while (*str) {
    char c = *str++;
    if (c >= 'a' && c <= 'z')
      c += 'A' - 'a';
    *dp-- = c;
  }
  printf("dp = %s\n", dp);
  return dp;
}


x86 assembly (clang, -O0):
<upcase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x9(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1182 <upcase+0x72>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x61,%eax
jl     1169 <upcase+0x59>
movsbl -0x19(%rbp),%eax
cmp    $0x7a,%eax
jg     1169 <upcase+0x59>
movsbl -0x19(%rbp),%eax
add    $0xffffffe0,%eax
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1124 <upcase+0x14>
mov    -0x18(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upcase>:
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%al
test   %al,%al
je     1155 <upcase+0x45>
add    $0x1,%rdi
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x61(%rax),%ecx
lea    -0x20(%rax),%edx
cmp    $0x1a,%cl
movzbl %al,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
mov    %cl,(%rbx)
add    $0xffffffffffffffff,%rbx
movzbl (%rdi),%eax
add    $0x1,%rdi
test   %al,%al
jne    1130 <upcase+0x20>
jmp    115a <upcase+0x4a>
lea    0xf(%rsp),%rbx
lea    0xe9f(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"dp = %s\0A\00"
define i8* @upcase(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i8
store i8* %0, i8** %2
store i8* %3, i8** %4
br label %6
6: ; preds = %26, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %30
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %2
%13 = load i8, i8* %11
store i8 %13, i8* %5
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp sge i32 %15, 97
br i1 %16, label %17, label %26
17: ; preds = %10
%18 = load i8, i8* %5
%19 = sext i8 %18 to i32
%20 = icmp sle i32 %19, 122
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i8, i8* %5
%23 = sext i8 %22 to i32
%24 = add nsw i32 %23, -32
%25 = trunc i32 %24 to i8
store i8 %25, i8* %5
br label %26
26: ; preds = %21, %17, %10
%27 = load i8, i8* %5
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %4
store i8 %27, i8* %28
br label %6
30: ; preds = %6
%31 = load i8*, i8** %4
%32 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %4
ret i8* %33
}

LLVM IR (-O2):
@.str = [9 x i8] c"dp = %s\0A\00"
define i8* @upcase(i8* nocapture %0) {
%2 = alloca i8
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %17, label %5
5: ; preds = %1, %5
%6 = phi i8 [ %15, %5 ], [ %3, %1 ]
%7 = phi i8* [ %14, %5 ], [ %2, %1 ]
%8 = phi i8* [ %9, %5 ], [ %0, %1 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = add i8 %6, -97
%11 = icmp ult i8 %10, 26
%12 = add i8 %6, -32
%13 = select i1 %11, i8 %12, i8 %6
%14 = getelementptr inbounds i8, i8* %7, i64 -1
store i8 %13, i8* %7
%15 = load i8, i8* %9
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %5
17: ; preds = %5, %1
%18 = phi i8* [ %2, %1 ], [ %14, %5 ]
%19 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %18)
ret i8* %18
}