#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 */
char tolower(char);
char toupper(char);
char *format(char *str) {
  if (str == NULL || *str == '\0')
    return str;
  char *s = str;
  *str = toupper(*str);
  while (*++str)
    *str = tolower(*str);
  return s;
}


x86 assembly (clang, -O0):
<format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1147 <format+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1154 <format+0x34>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <format+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,0x1(%rax)
je     11a2 <format+0x82>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1170 <format+0x50>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     1166 <format+0x46>
mov    (%r14),%al
test   %al,%al
je     1166 <format+0x46>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%r14)
mov    0x1(%r14),%al
test   %al,%al
je     1166 <format+0x46>
lea    0x2(%r14),%rbx
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <format+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @format(i8* returned %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
%7 = tail call signext i8 @toupper(i8 signext %4)
store i8 %7, i8* %0
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %6, %11
%12 = phi i8 [ %16, %11 ], [ %9, %6 ]
%13 = phi i8* [ %15, %11 ], [ %8, %6 ]
%14 = tail call signext i8 @tolower(i8 signext %12)
store i8 %14, i8* %13
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %11
18: ; preds = %11, %6, %1, %3
ret i8* %0
}