#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 */
scalar_t__ isatty(int);
scalar_t__ my_isatty(int);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  printf("isatty fd 0: %s\n", isatty(0) ? "tty" : "not a tty");
  printf("isatty fd 1: %s\n", isatty(1) ? "tty" : "not a tty");
  printf("isatty fd 2: %s\n", isatty(2) ? "tty" : "not a tty");
  printf("my_isatty fd 0: %s\n", my_isatty(0) ? "tty" : "not a tty");
  printf("my_isatty fd 1: %s\n", my_isatty(1) ? "tty" : "not a tty");
  printf("my_isatty fd 2: %s\n", my_isatty(2) ? "tty" : "not a tty");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xeb0(%rip),%rsi
lea    0xeaf(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xe81(%rip),%rsi
lea    0xe80(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1030 <isatty@plt>
mov    %rax,%rcx
lea    0xe52(%rip),%rsi
lea    0xe51(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <my_isatty@plt>
mov    %rax,%rcx
lea    0xe26(%rip),%rsi
lea    0xe25(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <my_isatty@plt>
mov    %rax,%rcx
lea    0xdf7(%rip),%rsi
lea    0xdf6(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1050 <my_isatty@plt>
mov    %rax,%rcx
lea    0xdc8(%rip),%rsi
lea    0xdc7(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rsi
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1030 <isatty@plt>
test   %rax,%rax
lea    0xebb(%rip),%r14
lea    0xeba(%rip),%rbx
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xeb3(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
test   %rax,%rax
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1030 <isatty@plt>
test   %rax,%rax
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <my_isatty@plt>
test   %rax,%rax
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <my_isatty@plt>
test   %rax,%rax
mov    %rbx,%rsi
cmove  %r14,%rsi
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1050 <my_isatty@plt>
test   %rax,%rax
cmove  %r14,%rbx
lea    0xe3e(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [17 x i8] c"isatty fd 0: %s\0A\00"
@.str.1 = [4 x i8] c"tty\00"
@.str.2 = [10 x i8] c"not a tty\00"
@.str.3 = [17 x i8] c"isatty fd 1: %s\0A\00"
@.str.4 = [17 x i8] c"isatty fd 2: %s\0A\00"
@.str.5 = [20 x i8] c"my_isatty fd 0: %s\0A\00"
@.str.6 = [20 x i8] c"my_isatty fd 1: %s\0A\00"
@.str.7 = [20 x i8] c"my_isatty fd 2: %s\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i64 @isatty(i32 0)
%3 = icmp ne i64 %2, 0
%4 = zext i1 %3 to i64
%5 = select i1 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%6 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i64 @isatty(i32 1)
%8 = icmp ne i64 %7, 0
%9 = zext i1 %8 to i64
%10 = select i1 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%11 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = call i64 @isatty(i32 2)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%16 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%17 = call i64 @my_isatty(i32 0)
%18 = icmp ne i64 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%21 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %20)
%22 = call i64 @my_isatty(i32 1)
%23 = icmp ne i64 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%26 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %25)
%27 = call i64 @my_isatty(i32 2)
%28 = icmp ne i64 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0)
%31 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"isatty fd 0: %s\0A\00"
@.str.1 = [4 x i8] c"tty\00"
@.str.2 = [10 x i8] c"not a tty\00"
@.str.3 = [17 x i8] c"isatty fd 1: %s\0A\00"
@.str.4 = [17 x i8] c"isatty fd 2: %s\0A\00"
@.str.5 = [20 x i8] c"my_isatty fd 0: %s\0A\00"
@.str.6 = [20 x i8] c"my_isatty fd 1: %s\0A\00"
@.str.7 = [20 x i8] c"my_isatty fd 2: %s\0A\00"
define i32 @main() {
%1 = tail call i64 @isatty(i32 0)
%2 = icmp eq i64 %1, 0
%3 = select i1 %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = tail call i64 @isatty(i32 1)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%9 = tail call i64 @isatty(i32 2)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %11)
%13 = tail call i64 @my_isatty(i32 0)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%17 = tail call i64 @my_isatty(i32 1)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%21 = tail call i64 @my_isatty(i32 2)
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %23)
ret i32 0
}