#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 *, char *);
int /*<<< orphan*/ putchar(int);
scalar_t__ strcmp(char *, char *);
int stub1(int);
int tolower(int);
int toupper(int);
int main(int argc, char *argv[]) {
  int c;
  int (*converter)(int c);
  if (strcmp(argv[0], "./upper") == 0)
    converter = &toupper;
  else if (strcmp(argv[0], "./lower") == 0)
    converter = &tolower;
  else {
    printf("Error: program name %s not recognized\n", argv[0]);
    return -1;
  }
  while ((c = getchar()) != EOF)
    putchar((*converter)(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),%rdi
lea    0xe9c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1183 <main+0x43>
mov    0x2e56(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11d4 <main+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe77(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11b0 <main+0x70>
mov    0x2e39(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11cf <main+0x8f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120e <main+0xce>
jmp    11d4 <main+0x94>
jmp    11d9 <main+0x99>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%eax
je     1207 <main+0xc7>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%edi
call   *%rax
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11d9 <main+0x99>
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
mov    %rsi,%rbx
mov    (%rsi),%rdi
lea    0xeae(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1186 <main+0x46>
mov    (%rbx),%rdi
lea    0xea2(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     118f <main+0x4f>
mov    (%rbx),%rsi
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    11c8 <main+0x88>
mov    0x2e43(%rip),%r14
jmp    1196 <main+0x56>
mov    0x2e4a(%rip),%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e42(%rip),%r15
cmp    (%r15),%eax
je     11c8 <main+0x88>
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    11b0 <main+0x70>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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