#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[]) {
  if (argc < 2) {
    printf("Usage:./a.out [tolower|toupper]\n");
    return 1;
  }
  int c;
  int (*func)(int);
  if (strcmp(argv[1], "tolower") == 0) {
    func = tolower;
  } else if (strcmp(argv[1], "toupper") == 0) {
    func = toupper;
  } else {
    printf("error:argument %s invalid\n", argv[1]);
    return 1;
  }
  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   $0x2,-0x8(%rbp)
jge    117a <main+0x3a>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1237 <main+0xf7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe98(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11a8 <main+0x68>
mov    0x2e41(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11fd <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe72(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d6 <main+0x96>
mov    0x2e03(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11f8 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1237 <main+0xf7>
jmp    11fd <main+0xbd>
jmp    1202 <main+0xc2>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%eax
je     1230 <main+0xf0>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%edi
call   *%rax
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1202 <main+0xc2>
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
jg     1170 <main+0x20>
lea    0xeca(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    11f8 <main+0xa8>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe82(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11b6 <main+0x66>
mov    0x8(%rbx),%rdi
lea    0xe75(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11bf <main+0x6f>
mov    0x8(%rbx),%rsi
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
jmp    11f8 <main+0xa8>
mov    0x2e23(%rip),%r14
jmp    11c6 <main+0x76>
mov    0x2e0a(%rip),%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2e12(%rip),%r15
cmp    (%r15),%eax
je     11f8 <main+0xa8>
xor    %ebx,%ebx
nopl   (%rax)
mov    %eax,%edi
call   *%r14
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%r15),%eax
jne    11e0 <main+0x90>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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