#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 /*<<< orphan*/);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ tolower(int);
int /*<<< orphan*/ toupper(int);
int main(int argc, char *argv[]) {
  argc = argc;
  int to_lower = (strstr(argv[0], "tolower") != NULL) ? 1 : 0;
  int c;
  while ((c = getchar()) != EOF)
    if (to_lower)
      putchar(tolower(c));
    else
      putchar(toupper(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    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe86(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%eax
je     11de <main+0x8e>
cmpl   $0x0,-0x14(%rbp)
je     11ca <main+0x7a>
mov    -0x18(%rbp),%edi
call   1060 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    11d9 <main+0x89>
mov    -0x18(%rbp),%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1193 <main+0x43>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    (%rsi),%rdi
lea    0xea2(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e74(%rip),%r14
jmp    1193 <main+0x43>
cs nopw 0x0(%rax,%rax,1)
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r14),%eax
je     11a6 <main+0x56>
mov    %eax,%edi
test   %rbx,%rbx
je     1180 <main+0x30>
call   1060 <tolower@plt>
jmp    1185 <main+0x35>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"tolower\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
store i32 %8, i32* %4
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32* @strstr(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32* %12, null
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 1, i32 0
store i32 %15, i32* %6
br label %16
16: ; preds = %31, %2
%17 = call i32 (...) @getchar()
store i32 %17, i32* %7
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %7
%25 = call i32 @tolower(i32 %24)
%26 = call i32 @putchar(i32 %25)
br label %31
27: ; preds = %20
%28 = load i32, i32* %7
%29 = call i32 @toupper(i32 %28)
%30 = call i32 @putchar(i32 %29)
br label %31
31: ; preds = %27, %23
br label %16
32: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"tolower\00"
@EOF = 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 ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
%6 = tail call i32 (...) @getchar()
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %21, label %9
9: ; preds = %2, %15
%10 = phi i32 [ %18, %15 ], [ %6, %2 ]
br i1 %5, label %13, label %11
11: ; preds = %9
%12 = tail call i32 @tolower(i32 %10)
br label %15
13: ; preds = %9
%14 = tail call i32 @toupper(i32 %10)
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %14, %13 ], [ %12, %11 ]
%17 = tail call i32 @putchar(i32 %16)
%18 = tail call i32 (...) @getchar()
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %9
21: ; preds = %15, %2
ret i32 0
}