#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*/ printf(char *);
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 c;
  if (argc < 2) {
    printf("No argument given (tolower or toupper)\n");
    return 1;
  } else if (strcmp(argv[1], "tolower") != 0 &&
             strcmp(argv[1], "toupper") != 0) {
    printf("Argument must be either 'tolower' or 'toupper'\n");
    return 1;
  }
  if (!strcmp("tolower", argv[1]))
    while ((c = getchar()) != EOF)
      putchar(tolower(c));
  else if (!strcmp("toupper", argv[1]))
    while ((c = getchar()) != EOF)
      putchar(toupper(c));
  else
    printf("Argument must be 'tolwer' or 'toupper'\n");
  return 0;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <main+0x153>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe81(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11ec <main+0x8c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11ec <main+0x8c>
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b3 <main+0x153>
jmp    11f1 <main+0x91>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe28(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1246 <main+0xe6>
jmp    1214 <main+0xb4>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%eax
je     1241 <main+0xe1>
mov    -0x14(%rbp),%edi
call   1080 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1214 <main+0xb4>
jmp    12ac <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xddb(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    129b <main+0x13b>
jmp    1269 <main+0x109>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d6e(%rip),%rcx
cmp    (%rcx),%eax
je     1296 <main+0x136>
mov    -0x14(%rbp),%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1269 <main+0x109>
jmp    12a7 <main+0x147>
lea    0xdc6(%rip),%rdi
call   1050 <printf@plt>
jmp    12ac <main+0x14c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebx
cmp    $0x2,%edi
jge    117f <main+0x1f>
lea    0xef1(%rip),%rdi
call   1050 <puts@plt>
jmp    126a <main+0x10a>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe73(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11bd <main+0x5d>
mov    0x8(%r14),%rdi
lea    0xe66(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11bd <main+0x5d>
lea    0xe84(%rip),%rdi
call   1050 <puts@plt>
jmp    126a <main+0x10a>
mov    0x8(%r14),%rsi
lea    0xe38(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f7 <main+0x97>
mov    0x8(%r14),%rsi
lea    0xe2b(%rip),%rdi
call   1060 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     122c <main+0xcc>
lea    0xe20(%rip),%rdi
call   1050 <puts@plt>
jmp    126a <main+0x10a>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2de1(%rip),%r14
cmp    (%r14),%eax
je     126a <main+0x10a>
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %eax,%edi
call   1080 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%r14),%eax
jne    1210 <main+0xb0>
jmp    126a <main+0x10a>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2dae(%rip),%r14
cmp    (%r14),%eax
je     126a <main+0x10a>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%r14),%eax
jne    1250 <main+0xf0>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [40 x i8] c"No argument given (tolower or toupper)\0A\00"
@.str.1 = [8 x i8] c"tolower\00"
@.str.2 = [8 x i8] c"toupper\00"
@.str.3 = [48 x i8] c"Argument must be either 'tolower' or 'toupper'\0A\00"
@EOF = global i32 0
@.str.4 = [40 x i8] c"Argument must be 'tolwer' or 'toupper'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %62
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %11
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %62
25: ; preds = %17, %11
br label %26
26: ; preds = %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %42, label %32
32: ; preds = %26
br label %33
33: ; preds = %37, %32
%34 = call i32 (...) @getchar()
store i32 %34, i32* %6
%35 = load i32, i32* @EOF
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* %6
%39 = call i32 @tolower(i32 %38)
%40 = call i32 @putchar(i32 %39)
br label %33
41: ; preds = %33
br label %61
42: ; preds = %26
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %58, label %48
48: ; preds = %42
br label %49
49: ; preds = %53, %48
%50 = call i32 (...) @getchar()
store i32 %50, i32* %6
%51 = load i32, i32* @EOF
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i32, i32* %6
%55 = call i32 @toupper(i32 %54)
%56 = call i32 @putchar(i32 %55)
br label %49
57: ; preds = %49
br label %60
58: ; preds = %42
%59 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %57
br label %61
61: ; preds = %60, %41
store i32 0, i32* %3
br label %62
62: ; preds = %61, %23, %9
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c"tolower\00"
@.str.2 = [8 x i8] c"toupper\00"
@EOF = global i32 0
@str = [39 x i8] c"Argument must be 'tolwer' or 'toupper'\00"
@str.5 = [47 x i8] c"Argument must be either 'tolower' or 'toupper'\00"
@str.6 = [39 x i8] c"No argument given (tolower or toupper)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %43, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %43
13: ; preds = %4, %9
%14 = load i8*, i8** %5
%15 = tail call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = tail call i32 (...) @getchar()
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %47, label %21
21: ; preds = %17, %21
%22 = phi i32 [ %25, %21 ], [ %18, %17 ]
%23 = tail call i32 @tolower(i32 %22)
%24 = tail call i32 @putchar(i32 %23)
%25 = tail call i32 (...) @getchar()
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %47, label %21
28: ; preds = %13
%29 = load i8*, i8** %5
%30 = tail call i64 @strcmp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %28
%33 = tail call i32 (...) @getchar()
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %47, label %36
36: ; preds = %32, %36
%37 = phi i32 [ %40, %36 ], [ %33, %32 ]
%38 = tail call i32 @toupper(i32 %37)
%39 = tail call i32 @putchar(i32 %38)
%40 = tail call i32 (...) @getchar()
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %40, %41
br i1 %42, label %47, label %36
43: ; preds = %28, %9, %2
%44 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0), %2 ], [ getelementptr inbounds ([47 x i8], [47 x i8]* @str.5, i64 0, i64 0), %9 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0), %28 ]
%45 = phi i32 [ 1, %2 ], [ 1, %9 ], [ 0, %28 ]
%46 = tail call i32 @puts(i8* dereferenceable(1) %44)
br label %47
47: ; preds = %36, %21, %43, %32, %17
%48 = phi i32 [ 0, %17 ], [ 0, %32 ], [ %45, %43 ], [ 0, %21 ], [ 0, %36 ]
ret i32 %48
}