#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);
scalar_t__ strcmp(char *, char *);
int tolower(int);
int toupper(int);
int main(int argc, char *argv[]) {
  int state = 0;
  int c;
  int (*convert)(int);
  if (argc == 1) {
    printf("usage \"./program -lower\" to lower case or \"./programa -upper\" "
           "to upper case and \"./program -default\" to no conversion\n");
    return 0;
  } else {
    if (strcmp("-lower", argv[1]) == 0)
      convert = tolower;
    else if (strcmp("-upper", argv[1]) == 0)
      convert = toupper;
    else if (strcmp("-default", argv[1]) == 0)
      state = 1;
    else {
      printf("Wrong option\n");
      return -1;
    }
  }
  if (state == 1)
    while ((c = getchar()) != EOF)
      putchar(c);
  else
    while ((c = getchar()) != EOF)
      putchar(convert(c));
  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)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    117f <main+0x3f>
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a5 <main+0x165>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xee9(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ad <main+0x6d>
mov    0x2e3c(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1227 <main+0xe7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xec2(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11db <main+0x9b>
mov    0x2dfe(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1222 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe9b(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1205 <main+0xc5>
movl   $0x1,-0x14(%rbp)
jmp    121d <main+0xdd>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a5 <main+0x165>
jmp    1222 <main+0xe2>
jmp    1227 <main+0xe7>
jmp    122c <main+0xec>
cmpl   $0x1,-0x14(%rbp)
jne    1266 <main+0x126>
jmp    123b <main+0xfb>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%eax
je     1261 <main+0x121>
mov    -0x18(%rbp),%edi
call   1030 <putchar@plt>
jmp    123b <main+0xfb>
jmp    129e <main+0x15e>
jmp    126b <main+0x12b>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d6c(%rip),%rcx
cmp    (%rcx),%eax
je     1299 <main+0x159>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%edi
call   *%rax
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    126b <main+0x12b>
jmp    129e <main+0x15e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x1,%edi
jne    115d <main+0x1d>
xor    %ebx,%ebx
lea    0xed1(%rip),%rdi
call   1040 <puts@plt>
jmp    11f8 <main+0xb8>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0xe95(%rip),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b2 <main+0x72>
mov    0x8(%rbx),%rsi
lea    0xe87(%rip),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11bb <main+0x7b>
mov    0x8(%rbx),%rsi
lea    0xe79(%rip),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1200 <main+0xc0>
mov    $0xffffffff,%ebx
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
jmp    11f8 <main+0xb8>
mov    0x2e27(%rip),%r14
jmp    11c2 <main+0x82>
mov    0x2e0e(%rip),%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e16(%rip),%r15
cmp    (%r15),%eax
je     11f8 <main+0xb8>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %eax,%edi
call   *%r14
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%r15),%eax
jne    11e0 <main+0xa0>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2dd8(%rip),%r14
cmp    (%r14),%eax
je     11f8 <main+0xb8>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%r14),%eax
jne    1220 <main+0xe0>
jmp    11f8 <main+0xb8>

LLVM IR (-O0):
@.str = [119 x i8] c"usage \22./program -lower\22 to lower case or \22./programa -upper\22 to upper case and \22./program -default\22 to no conversion\0A\00"
@.str.1 = [7 x i8] c"-lower\00"
@.str.2 = [7 x i8] c"-upper\00"
@.str.3 = [9 x i8] c"-default\00"
@.str.4 = [14 x i8] c"Wrong option\0A\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
%8 = alloca i32 (i32)*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([119 x i8], [119 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %63
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 (i32)* @tolower, i32 (i32)** %8
br label %38
20: ; preds = %13
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 (i32)* @toupper, i32 (i32)** %8
br label %37
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 1, i32* %6
br label %36
34: ; preds = %27
%35 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %63
36: ; preds = %33
br label %37
37: ; preds = %36, %26
br label %38
38: ; preds = %37, %19
br label %39
39: ; preds = %38
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %51
42: ; preds = %39
br label %43
43: ; preds = %47, %42
%44 = call i32 (...) @getchar()
store i32 %44, i32* %7
%45 = load i32, i32* @EOF
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* %7
%49 = call i32 @putchar(i32 %48)
br label %43
50: ; preds = %43
br label %62
51: ; preds = %39
br label %52
52: ; preds = %56, %51
%53 = call i32 (...) @getchar()
store i32 %53, i32* %7
%54 = load i32, i32* @EOF
%55 = icmp ne i32 %53, %54
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = load i32 (i32)*, i32 (i32)** %8
%58 = load i32, i32* %7
%59 = call i32 %57(i32 %58)
%60 = call i32 @putchar(i32 %59)
br label %52
61: ; preds = %52
br label %62
62: ; preds = %61, %50
store i32 0, i32* %3
br label %63
63: ; preds = %62, %34, %11
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"-lower\00"
@.str.2 = [7 x i8] c"-upper\00"
@.str.3 = [9 x i8] c"-default\00"
@EOF = global i32 0
@str = [13 x i8] c"Wrong option\00"
@str.5 = [118 x i8] c"usage \22./program -lower\22 to lower case or \22./programa -upper\22 to upper case and \22./program -default\22 to no conversion\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %39, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = tail call i64 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %22, label %39
17: ; preds = %4, %9
%18 = phi i32 (i32)* [ @toupper, %9 ], [ @tolower, %4 ]
%19 = tail call i32 (...) @getchar()
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %43, label %32
22: ; preds = %13
%23 = tail call i32 (...) @getchar()
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %43, label %26
26: ; preds = %22, %26
%27 = phi i32 [ %29, %26 ], [ %23, %22 ]
%28 = tail call i32 @putchar(i32 %27)
%29 = tail call i32 (...) @getchar()
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %43, label %26
32: ; preds = %17, %32
%33 = phi i32 [ %36, %32 ], [ %19, %17 ]
%34 = tail call i32 %18(i32 %33)
%35 = tail call i32 @putchar(i32 %34)
%36 = tail call i32 (...) @getchar()
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %36, %37
br i1 %38, label %43, label %32
39: ; preds = %13, %2
%40 = phi i8* [ getelementptr inbounds ([118 x i8], [118 x i8]* @str.5, i64 0, i64 0), %2 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0), %13 ]
%41 = phi i32 [ 0, %2 ], [ -1, %13 ]
%42 = tail call i32 @puts(i8* dereferenceable(1) %40)
br label %43
43: ; preds = %26, %32, %39, %17, %22
%44 = phi i32 [ 0, %22 ], [ 0, %17 ], [ %41, %39 ], [ 0, %32 ], [ 0, %26 ]
ret i32 %44
}