#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);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int stub1(int);
int tolower(int);
int toupper(int);
int main(int argc, char *argv[]) {
  int (*f)(int) = toupper, c;
  char *name;
  for (name = *argv + strlen(*argv) - 1; name != *argv && *name != '/'; name--)
    ;
  if (name != *argv)
    name++;
  if (!strcmp("lower", name)) {
    f = tolower;
  }
  while ((c = getchar()) != EOF)
    putchar((*f)(c));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
mov    %al,-0x31(%rbp)
je     11b2 <main+0x72>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11c2 <main+0x82>
jmp    11d8 <main+0x98>
jmp    11c7 <main+0x87>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    118c <main+0x4c>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
je     11f5 <main+0xb5>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe00(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1219 <main+0xd9>
mov    0x2dcb(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    121e <main+0xde>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%eax
je     124c <main+0x10c>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%edi
call   *%rax
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    121e <main+0xde>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    (%rsi),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
mov    (%rbx),%rsi
add    %r14,%rax
add    $0xffffffffffffffff,%rax
xchg   %ax,%ax
cmp    %rsi,%rax
je     1178 <main+0x38>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,(%rax)
mov    %rcx,%rax
jne    1160 <main+0x20>
add    $0x2,%rcx
mov    %rcx,%rsi
lea    0xe81(%rip),%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    1191 <main+0x51>
mov    0x2e51(%rip),%rbx
jmp    1198 <main+0x58>
mov    0x2e38(%rip),%rbx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e42(%rip),%r14
cmp    (%r14),%eax
je     11c7 <main+0x87>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   *%rbx
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%r14),%eax
jne    11b0 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [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 i32 (i32)*
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 (i32)* @toupper, i32 (i32)** %6
%9 = load i8**, i8*** %5
%10 = load i8*, i8** %9
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
store i8* %16, i8** %8
br label %17
17: ; preds = %30, %2
%18 = load i8*, i8** %8
%19 = load i8**, i8*** %5
%20 = load i8*, i8** %19
%21 = icmp ne i8* %18, %20
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i8*, i8** %8
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 47
br label %27
27: ; preds = %22, %17
%28 = phi i1 [ false, %17 ], [ %26, %22 ]
br i1 %28, label %29, label %33
29: ; preds = %27
br label %30
30: ; preds = %29
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %8
br label %17
33: ; preds = %27
%34 = load i8*, i8** %8
%35 = load i8**, i8*** %5
%36 = load i8*, i8** %35
%37 = icmp ne i8* %34, %36
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i8*, i8** %8
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %8
br label %41
41: ; preds = %38, %33
%42 = load i8*, i8** %8
%43 = call i32 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %41
store i32 (i32)* @tolower, i32 (i32)** %6
br label %46
46: ; preds = %45, %41
br label %47
47: ; preds = %51, %46
%48 = call i32 (...) @getchar()
store i32 %48, i32* %7
%49 = load i32, i32* @EOF
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = load i32 (i32)*, i32 (i32)** %6
%53 = load i32, i32* %7
%54 = call i32 %52(i32 %53)
%55 = call i32 @putchar(i32 %54)
br label %47
56: ; preds = %47
ret i32 0
}

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