#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, lcase;
  char *arg;
  arg = *++argv;
  if (strcmp(arg, "lower") == 0) {
    lcase = 0;
  } else if (strcmp(arg, "upper") == 0) {
    lcase = 1;
  } else {
    printf("no commond line argument!\n");
    return 0;
  }
  while ((c = getchar()) != EOF) {
    if (lcase == 0) {
      putchar(tolower(c));
    } else {
      putchar(toupper(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)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11b3 <main+0x53>
movl   $0x0,-0x18(%rbp)
jmp    11f6 <main+0x96>
mov    -0x20(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d9 <main+0x79>
movl   $0x1,-0x18(%rbp)
jmp    11f1 <main+0x91>
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124d <main+0xed>
jmp    11f6 <main+0x96>
jmp    11fb <main+0x9b>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%eax
je     1246 <main+0xe6>
cmpl   $0x0,-0x18(%rbp)
jne    1232 <main+0xd2>
mov    -0x14(%rbp),%edi
call   1080 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1241 <main+0xe1>
mov    -0x14(%rbp),%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11fb <main+0x9b>
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    0x8(%rsi),%r14
lea    0xe91(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a9 <main+0x49>
lea    0xe80(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a9 <main+0x49>
lea    0xe72(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2e31(%rip),%r14
jmp    11d3 <main+0x73>
nopl   0x0(%rax)
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%r14),%eax
je     119f <main+0x3f>
mov    %eax,%edi
test   %rbx,%rbx
jne    11c0 <main+0x60>
call   1080 <tolower@plt>
jmp    11c5 <main+0x65>

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

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