#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__ strindex(char *, char *);
int tolower(int);
int toupper(int);
int main(int argc, char *argv[]) {
  int c;
  int (*func)(int) = (strindex(argv[0], "upper") < 0) ? tolower : toupper;
  while ((c = getchar()) != EOF)
    (void)putchar(func(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    0xeac(%rip),%rsi
call   1050 <strindex@plt>
mov    %rax,%rdx
mov    0x2e6d(%rip),%rax
mov    0x2e76(%rip),%rcx
cmp    $0x0,%rdx
cmovl  %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%eax
je     11a4 <main+0x74>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%edi
call   *%rax
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1176 <main+0x46>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%rdi
lea    0xec2(%rip),%rsi
call   1050 <strindex@plt>
test   %rax,%rax
jns    1151 <main+0x21>
mov    0x2e91(%rip),%rbx
jmp    1158 <main+0x28>
mov    0x2e78(%rip),%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2e82(%rip),%r14
cmp    (%r14),%eax
je     1187 <main+0x57>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   *%rbx
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r14),%eax
jne    1170 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"upper\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 @strindex(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = icmp slt i64 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i32 (i32)* @tolower, i32 (i32)* @toupper
store i32 (i32)* %14, i32 (i32)** %7
br label %15
15: ; preds = %19, %2
%16 = call i32 (...) @getchar()
store i32 %16, i32* %6
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32 (i32)*, i32 (i32)** %7
%21 = load i32, i32* %6
%22 = call i32 %20(i32 %21)
%23 = call i32 @putchar(i32 %22)
br label %15
24: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"upper\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i64 @strindex(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp slt i64 %4, 0
%6 = select i1 %5, i32 (i32)* @tolower, i32 (i32)* @toupper
%7 = tail call i32 (...) @getchar()
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %17, label %10
10: ; preds = %2, %10
%11 = phi i32 [ %14, %10 ], [ %7, %2 ]
%12 = tail call i32 %6(i32 %11)
%13 = tail call i32 @putchar(i32 %12)
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %10
17: ; preds = %10, %2
ret i32 0
}