#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int getchar();
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *strstr(char *, char *);
int tolower(int);
int toupper(int);
int main(int argc, char *argv[]) {
  char *prog_name = argv[0];
  int (*conversion_func)(int);
  if (strstr(prog_name, "upper") != NULL) {
    conversion_func = toupper;
  } else if (strstr(prog_name, "lower") != NULL) {
    conversion_func = tolower;
  } else {
    fprintf(stderr, "program name must contain \"%s\" or \"%s\"\n", "upper",
            "lower");
    exit(EXIT_FAILURE);
  }
  int current_char = EOF;
  while ((current_char = getchar()) != EOF) {
    putchar(conversion_func(current_char));
  }
  return EXIT_SUCCESS;
}


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)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     119b <main+0x4b>
mov    0x2e26(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11fb <main+0xab>
mov    -0x18(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11c5 <main+0x75>
mov    0x2e24(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11f6 <main+0xa6>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
lea    0xe24(%rip),%rdx
lea    0xe23(%rip),%rcx
call   1050 <fprintf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    11fb <main+0xab>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%eax
je     1235 <main+0xe5>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%edi
call   *%rax
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1207 <main+0xb7>
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%rbx
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     1174 <main+0x24>
mov    0x2e46(%rip),%rbx
jmp    118f <main+0x3f>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     11d8 <main+0x88>
mov    0x2e51(%rip),%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e4b(%rip),%r14
cmp    (%r14),%eax
je     11c7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%edi
call   *%rbx
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r14),%eax
jne    11b0 <main+0x60>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
lea    0xe11(%rip),%rdx
lea    0xe10(%rip),%rcx
call   1050 <fprintf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"upper\00"
@.str.1 = [6 x i8] c"lower\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"program name must contain \22%s\22 or \22%s\22\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32 (i32)*
%8 = alloca i32
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, i64 0
%11 = load i8*, i8** %10
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = call i32* @strstr(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 (i32)* @toupper, i32 (i32)** %7
br label %27
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = call i32* @strstr(i8* %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 (i32)* @tolower, i32 (i32)** %7
br label %26
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %20
br label %27
27: ; preds = %26, %15
%28 = load i32, i32* @EOF
store i32 %28, i32* %8
br label %29
29: ; preds = %33, %27
%30 = call i32 (...) @getchar()
store i32 %30, i32* %8
%31 = load i32, i32* @EOF
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = load i32 (i32)*, i32 (i32)** %7
%35 = load i32, i32* %8
%36 = call i32 %34(i32 %35)
%37 = call i32 @putchar(i32 %36)
br label %29
38: ; preds = %29
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}

LLVM IR (-O2):
@.str = [6 x i8] c"upper\00"
@.str.1 = [6 x i8] c"lower\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"program name must contain \22%s\22 or \22%s\22\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = tail call i32* @strstr(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %6, %2
%15 = phi i32 (i32)* [ @toupper, %2 ], [ @tolower, %6 ]
%16 = tail call i32 (...) @getchar()
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %26, label %19
19: ; preds = %14, %19
%20 = phi i32 [ %23, %19 ], [ %16, %14 ]
%21 = tail call i32 %15(i32 %20)
%22 = tail call i32 @putchar(i32 %21)
%23 = tail call i32 (...) @getchar()
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %19
26: ; preds = %19, %14
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}