#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int getchar();
int /*<<< orphan*/ printf(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 ErrorStatus = 0;
  int (*convert)(int c) = NULL;
  int c = 0;
  if (0 == ErrorStatus) {
    if (0 >= argc) {
      printf("Your environment has not provided a single argument for the "
             "program name.\n");
      ErrorStatus = 1;
    }
  }
  if (0 == ErrorStatus) {
    if (0 == strcmp(argv[0], "lower")) {
      convert = tolower;
    } else if (0 == strcmp(argv[0], "upper")) {
      convert = toupper;
    } else {
      printf("This program performs two functions.\n");
      printf("If the executable is named lower then it converts all the input "
             "on stdin to lowercase.\n");
      printf("If the executable is named upper then it converts all the input "
             "on stdin to uppercase.\n");
      printf("As you have named it %s it prints this message.\n", argv[0]);
      ErrorStatus = 2;
    }
  }
  if (0 == ErrorStatus) {
    while (EOF != (c = getchar())) {
      putchar((*convert)(c));
    }
  }
  return 0 == ErrorStatus ? EXIT_SUCCESS : EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    119c <main+0x5c>
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jl     1197 <main+0x57>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    119c <main+0x5c>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    1259 <main+0x119>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe96(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11d8 <main+0x98>
mov    0x2e11(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1254 <main+0x114>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe6b(%rip),%rsi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1209 <main+0xc9>
mov    0x2dc0(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    124f <main+0x10f>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xeec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x14(%rbp)
jmp    1254 <main+0x114>
jmp    1259 <main+0x119>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    12a6 <main+0x166>
jmp    1269 <main+0x129>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
mov    %ecx,-0x24(%rbp)
cmp    %ecx,%eax
je     12a1 <main+0x161>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%edi
call   *%rax
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1269 <main+0x129>
jmp    12a6 <main+0x166>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    12c2 <main+0x182>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    12ce <main+0x18e>
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    11bd <main+0x6d>
mov    %rsi,%rbx
mov    (%rsi),%rdi
lea    0xe98(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d2 <main+0x82>
mov    (%rbx),%rdi
lea    0xe8a(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11db <main+0x8b>
lea    0xeb0(%rip),%rdi
call   1040 <puts@plt>
lea    0xec9(%rip),%rdi
call   1040 <puts@plt>
lea    0xf14(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%rsi
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c9 <main+0x79>
lea    0xf4c(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e00(%rip),%r14
jmp    1219 <main+0xc9>
mov    0x2e07(%rip),%rbx
jmp    11e2 <main+0x92>
mov    0x2dde(%rip),%rbx
mov    0x2dff(%rip),%r15
mov    (%r15),%ebp
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2dce(%rip),%r14
cmp    %eax,%ebp
je     1219 <main+0xc9>
xchg   %ax,%ax
mov    %eax,%edi
call   *%rbx
mov    %eax,%edi
call   1030 <putchar@plt>
mov    (%r15),%ebp
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    %eax,%ebp
jne    1200 <main+0xb0>
mov    (%r14),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [75 x i8] c"Your environment has not provided a single argument for the program name.\0A\00"
@.str.1 = [6 x i8] c"lower\00"
@.str.2 = [6 x i8] c"upper\00"
@.str.3 = [38 x i8] c"This program performs two functions.\0A\00"
@.str.4 = [88 x i8] c"If the executable is named lower then it converts all the input on stdin to lowercase.\0A\00"
@.str.5 = [88 x i8] c"If the executable is named upper then it converts all the input on stdin to uppercase.\0A\00"
@.str.6 = [49 x i8] c"As you have named it %s it prints this message.\0A\00"
@EOF = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = 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)*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 (i32)* null, i32 (i32)** %7
store i32 0, i32* %8
%9 = load i32, i32* %6
%10 = icmp eq i32 0, %9
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sge i32 0, %12
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %16
16: ; preds = %14, %11
br label %17
17: ; preds = %16, %2
%18 = load i32, i32* %6
%19 = icmp eq i32 0, %18
br i1 %19, label %20, label %44
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 0, %24
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 (i32)* @tolower, i32 (i32)** %7
br label %43
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 0, %31
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 (i32)* @toupper, i32 (i32)** %7
br label %42
34: ; preds = %27
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.5, i64 0, i64 0))
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %40)
store i32 2, i32* %6
br label %42
42: ; preds = %34, %33
br label %43
43: ; preds = %42, %26
br label %44
44: ; preds = %43, %17
%45 = load i32, i32* %6
%46 = icmp eq i32 0, %45
br i1 %46, label %47, label %58
47: ; preds = %44
br label %48
48: ; preds = %52, %47
%49 = load i32, i32* @EOF
%50 = call i32 (...) @getchar()
store i32 %50, i32* %8
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i32 (i32)*, i32 (i32)** %7
%54 = load i32, i32* %8
%55 = call i32 %53(i32 %54)
%56 = call i32 @putchar(i32 %55)
br label %48
57: ; preds = %48
br label %58
58: ; preds = %57, %44
%59 = load i32, i32* %6
%60 = icmp eq i32 0, %59
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = load i32, i32* @EXIT_SUCCESS
br label %65
63: ; preds = %58
%64 = load i32, i32* @EXIT_FAILURE
br label %65
65: ; preds = %63, %61
%66 = phi i32 [ %62, %61 ], [ %64, %63 ]
ret i32 %66
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"lower\00"
@.str.2 = [6 x i8] c"upper\00"
@.str.6 = [49 x i8] c"As you have named it %s it prints this message.\0A\00"
@EOF = global i32 0
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@str = [37 x i8] c"This program performs two functions.\00"
@str.7 = [87 x i8] c"If the executable is named lower then it converts all the input on stdin to lowercase.\00"
@str.8 = [87 x i8] c"If the executable is named upper then it converts all the input on stdin to uppercase.\00"
@str.9 = [74 x i8] c"Your environment has not provided a single argument for the program name.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @str.9, i64 0, i64 0))
br label %32
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i64 @strcmp(i8* %7, 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 %20, label %10
10: ; preds = %6
%11 = load i8*, i8** %1
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @str.7, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @str.8, i64 0, i64 0))
%18 = load i8*, i8** %1
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i8* %18)
br label %32
20: ; preds = %10, %6
%21 = phi i32 (i32)* [ @tolower, %6 ], [ @toupper, %10 ]
%22 = load i32, i32* @EOF
%23 = tail call i32 (...) @getchar()
%24 = icmp eq i32 %22, %23
br i1 %24, label %32, label %25
25: ; preds = %20, %25
%26 = phi i32 [ %30, %25 ], [ %23, %20 ]
%27 = tail call i32 %21(i32 %26)
%28 = tail call i32 @putchar(i32 %27)
%29 = load i32, i32* @EOF
%30 = tail call i32 (...) @getchar()
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %25
32: ; preds = %25, %20, %4, %14
%33 = phi i32* [ @EXIT_FAILURE, %14 ], [ @EXIT_FAILURE, %4 ], [ @EXIT_SUCCESS, %20 ], [ @EXIT_SUCCESS, %25 ]
%34 = load i32, i32* %33
ret i32 %34
}