#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*/ putchar(int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int tolower(int);
int toupper(int);
int main(int argc, char **argv) {
  char name[100] = {0};
  char i, *p;
  int c;
  int toupper_flag = 0;
  i = 0;
  while (argv[0][i++] != '\0') {
    if (argv[0][i] == '/')
      p = argv[0] + i + 1;
  }
  strncpy(name, p, 5);
  if (strcmp(name, "upper") == 0)
    toupper_flag = 1;
  else if (strcmp(name, "lower") == 0)
    toupper_flag = 0;
  else
    return -1;
  while ((c = getchar()) != EOF) {
    if (toupper_flag == 1)
      c = toupper(c);
    else
      c = tolower(c);
    putchar(c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
movl   $0x0,-0x98(%rbp)
movb   $0x0,-0x81(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x81(%rbp),%cl
mov    %cl,%dl
add    $0x1,%dl
mov    %dl,-0x81(%rbp)
movsbq %cl,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1213 <main+0xa3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbq -0x81(%rbp),%rcx
ff
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    120e <main+0x9e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl -0x81(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
jmp    11aa <main+0x3a>
lea    -0x80(%rbp),%rdi
mov    -0x90(%rbp),%rsi
mov    $0x5,%edx
call   1040 <strncpy@plt>
lea    -0x80(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1251 <main+0xe1>
movl   $0x1,-0x98(%rbp)
jmp    128b <main+0x11b>
lea    -0x80(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    127a <main+0x10a>
movl   $0x0,-0x98(%rbp)
jmp    1286 <main+0x116>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f7 <main+0x187>
jmp    128b <main+0x11b>
jmp    1290 <main+0x120>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %eax,-0x94(%rbp)
mov    0x2d44(%rip),%rcx
cmp    (%rcx),%eax
je     12f0 <main+0x180>
cmpl   $0x1,-0x98(%rbp)
jne    12cf <main+0x15f>
mov    -0x94(%rbp),%edi
call   1050 <toupper@plt>
mov    %eax,-0x94(%rbp)
jmp    12e0 <main+0x170>
mov    -0x94(%rbp),%edi
call   1090 <tolower@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%edi
call   1030 <putchar@plt>
jmp    1290 <main+0x120>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
mov    (%rsi),%rax
mov    $0x1,%cl
cs nopw 0x0(%rax,%rax,1)
nop
movsbq %cl,%rcx
movzbl (%rax,%rcx,1),%edx
cmp    $0x2f,%dl
lea    0x1(%rax,%rcx,1),%rdi
cmove  %rdi,%rsi
add    $0x1,%cl
test   %dl,%dl
jne    11a0 <main+0x40>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x5,%edx
call   1040 <strncpy@plt>
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11fb <main+0x9b>
lea    0xe1d(%rip),%rsi
mov    %rsp,%rdi
call   1060 <strcmp@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    1210 <main+0xb0>
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2ddd(%rip),%r14
cmp    (%r14),%eax
jne    121b <main+0xbb>
mov    %ebp,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %ebp,%ebp
jmp    1238 <main+0xd8>
nop
call   1080 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    (%r14),%eax
je     1210 <main+0xb0>
mov    %eax,%edi
test   %rbx,%rbx
jne    1220 <main+0xc0>
call   1050 <toupper@plt>
jmp    1225 <main+0xc5>

LLVM IR (-O0):
@.str = [6 x i8] c"upper\00"
@.str.1 = [6 x i8] c"lower\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [100 x i8]* %6 to i8*
store i32 0, i32* %10
store i8 0, i8* %7
br label %12
12: ; preds = %42, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i8, i8* %7
%17 = add i8 %16, 1
store i8 %17, i8* %7
%18 = sext i8 %16 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %43
23: ; preds = %12
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = load i8, i8* %7
%28 = sext i8 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br i1 %32, label %33, label %42
33: ; preds = %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = load i8, i8* %7
%38 = sext i8 %37 to i32
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8* %41, i8** %8
br label %42
42: ; preds = %33, %23
br label %12
43: ; preds = %12
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%45 = load i8*, i8** %8
%46 = call i32 @strncpy(i8* %44, i8* %45, i32 5)
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %43
store i32 1, i32* %10
br label %58
51: ; preds = %43
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %51
store i32 0, i32* %10
br label %57
56: ; preds = %51
store i32 -1, i32* %3
br label %76
57: ; preds = %55
br label %58
58: ; preds = %57, %50
br label %59
59: ; preds = %72, %58
%60 = call i32 (...) @getchar()
store i32 %60, i32* %9
%61 = load i32, i32* @EOF
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %75
63: ; preds = %59
%64 = load i32, i32* %10
%65 = icmp eq i32 %64, 1
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = load i32, i32* %9
%68 = call i32 @toupper(i32 %67)
store i32 %68, i32* %9
br label %72
69: ; preds = %63
%70 = load i32, i32* %9
%71 = call i32 @tolower(i32 %70)
store i32 %71, i32* %9
br label %72
72: ; preds = %69, %66
%73 = load i32, i32* %9
%74 = call i32 @putchar(i32 %73)
br label %59
75: ; preds = %59
store i32 0, i32* %3
br label %76
76: ; preds = %75, %56
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [6 x i8] c"upper\00"
@.str.1 = [6 x i8] c"lower\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br label %8
8: ; preds = %2, %8
%9 = phi i8 [ %17, %8 ], [ 1, %2 ]
%10 = phi i8* [ %16, %8 ], [ undef, %2 ]
%11 = sext i8 %9 to i64
%12 = getelementptr inbounds i8, i8* %5, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
%15 = getelementptr inbounds i8, i8* %12, i64 1
%16 = select i1 %14, i8* %15, i8* %10
%17 = add i8 %9, 1
%18 = icmp eq i8 %13, 0
br i1 %18, label %19, label %8
19: ; preds = %8
%20 = call i32 @strncpy(i8* %4, i8* %16, i32 5)
%21 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %42
26: ; preds = %23, %19
%27 = call i32 (...) @getchar()
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %42, label %30
30: ; preds = %26, %36
%31 = phi i32 [ %39, %36 ], [ %27, %26 ]
br i1 %22, label %32, label %34
32: ; preds = %30
%33 = call i32 @toupper(i32 %31)
br label %36
34: ; preds = %30
%35 = call i32 @tolower(i32 %31)
br label %36
36: ; preds = %34, %32
%37 = phi i32 [ %33, %32 ], [ %35, %34 ]
%38 = call i32 @putchar(i32 %37)
%39 = call i32 (...) @getchar()
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %30
42: ; preds = %36, %26, %23
%43 = phi i32 [ -1, %23 ], [ 0, %26 ], [ 0, %36 ]
ret i32 %43
}