#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 stub1(int);
int stub2(int);
int tolower(int);
int toupper(int);
int main(int argc, char *argv[]) {
  int (*func)(int);
  int c;
  if (argc > 0) {
    if (strcmp("upper", argv[0]) == 0) {
      func = toupper;
    } else if (strcmp("lower", argv[0]) == 0)
      func = tolower;
    else {
      printf("Error argument\n");
      return -1;
    }
  } else {
    printf("Error argument\n");
    return -1;
  }
  putchar((*func)('a'));
  while ((c = getchar()) != EOF)
    putchar((*func)(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)
cmpl   $0x0,-0x8(%rbp)
jle    11dc <main+0x9c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    118d <main+0x4d>
mov    0x2e4c(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11d7 <main+0x97>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6b(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ba <main+0x7a>
mov    0x2e2f(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11d2 <main+0x92>
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <main+0xf8>
jmp    11d7 <main+0x97>
jmp    11f4 <main+0xb4>
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1238 <main+0xf8>
mov    $0x61,%edi
call   *-0x18(%rbp)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%eax
je     1231 <main+0xf1>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%edi
call   *%rax
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1203 <main+0xc3>
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
test   %edi,%edi
jle    1174 <main+0x34>
mov    %rsi,%rbx
mov    (%rsi),%rsi
lea    0xeaa(%rip),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1187 <main+0x47>
mov    (%rbx),%rsi
lea    0xe9c(%rip),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1190 <main+0x50>
lea    0xe91(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
jmp    11d8 <main+0x98>
mov    0x2e42(%rip),%r14
jmp    1197 <main+0x57>
mov    0x2e49(%rip),%r14
mov    $0x61,%edi
call   *%r14
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e32(%rip),%r15
cmp    (%r15),%eax
je     11d8 <main+0x98>
xor    %ebx,%ebx
nopl   (%rax)
mov    %eax,%edi
call   *%r14
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%r15),%eax
jne    11c0 <main+0x80>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"upper\00"
@.str.1 = [6 x i8] c"lower\00"
@.str.2 = [16 x i8] c"Error argument\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 (i32)*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %28
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 (i32)* @toupper, i32 (i32)** %6
br label %27
17: ; preds = %10
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 (i32)* @tolower, i32 (i32)** %6
br label %26
24: ; preds = %17
%25 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %44
26: ; preds = %23
br label %27
27: ; preds = %26, %16
br label %30
28: ; preds = %2
%29 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %44
30: ; preds = %27
%31 = load i32 (i32)*, i32 (i32)** %6
%32 = call i32 %31(i32 97)
%33 = call i32 @putchar(i32 %32)
br label %34
34: ; preds = %38, %30
%35 = call i32 (...) @getchar()
store i32 %35, i32* %7
%36 = load i32, i32* @EOF
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i32 (i32)*, i32 (i32)** %6
%40 = load i32, i32* %7
%41 = call i32 %39(i32 %40)
%42 = call i32 @putchar(i32 %41)
br label %34
43: ; preds = %34
store i32 0, i32* %3
br label %44
44: ; preds = %43, %28, %24
%45 = load i32, i32* %3
ret i32 %45
}

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