#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 EOF;
int getchar();
int /*<<< orphan*/ putchar(int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ tolower(int);
int /*<<< orphan*/ toupper(int);
int main(int argc, char *argv[]) {
  int to_upper = 1;
  int c;
  if (strcmp(argv[0], "lower"))
    to_upper = 0;
  while ((c = getchar()) != EOF) {
    if (to_upper)
      putchar(toupper(c));
    else
      putchar(tolower(c));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe85(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1191 <main+0x41>
movl   $0x0,-0x14(%rbp)
jmp    1196 <main+0x46>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%eax
je     11e1 <main+0x91>
cmpl   $0x0,-0x14(%rbp)
je     11cd <main+0x7d>
mov    -0x18(%rbp),%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11dc <main+0x8c>
mov    -0x18(%rbp),%edi
call   1070 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1196 <main+0x46>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%rdi
lea    0xea2(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e74(%rip),%r14
jmp    1193 <main+0x43>
cs nopw 0x0(%rax,%rax,1)
call   1070 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%r14),%eax
je     11a6 <main+0x56>
mov    %eax,%edi
test   %rbx,%rbx
jne    1180 <main+0x30>
call   1040 <toupper@plt>
jmp    1185 <main+0x35>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"lower\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %6
br label %14
14: ; preds = %13, %2
br label %15
15: ; preds = %30, %14
%16 = call i32 (...) @getchar()
store i32 %16, i32* %7
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* %7
%24 = call i32 @toupper(i32 %23)
%25 = call i32 @putchar(i32 %24)
br label %30
26: ; preds = %19
%27 = load i32, i32* %7
%28 = call i32 @tolower(i32 %27)
%29 = call i32 @putchar(i32 %28)
br label %30
30: ; preds = %26, %22
br label %15
31: ; preds = %15
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"lower\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
%6 = tail call i32 (...) @getchar()
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %21, label %9
9: ; preds = %2, %15
%10 = phi i32 [ %18, %15 ], [ %6, %2 ]
br i1 %5, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @toupper(i32 %10)
br label %15
13: ; preds = %9
%14 = tail call i32 @tolower(i32 %10)
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %14, %13 ], [ %12, %11 ]
%17 = tail call i32 @putchar(i32 %16)
%18 = tail call i32 (...) @getchar()
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %9
21: ; preds = %15, %2
ret i32 0
}