#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);
int /*<<< orphan*/ printf(char *, int, char *, char *);
char *ttyname(int);
int main(int argc, char *argv[]) {
  int i;
  for (i = 0; i <= 3; ++i) {
    printf("fd %d: ttyname:%s, %s a tty!\n", i, ttyname(i),
           isatty(i) ? "is" : "isn't");
  }
  return 0;
}


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)
cmpl   $0x3,-0x14(%rbp)
jg     11ab <main+0x7b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <ttyname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <isatty@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    %rax,%rdi
lea    0xe9f(%rip),%rcx
lea    0xe95(%rip),%rax
cmp    $0x0,%rdi
cmovne %rax,%rcx
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <ttyname@plt>
mov    %rax,%r15
xor    %edi,%edi
call   1030 <isatty@plt>
test   %rax,%rax
lea    0xece(%rip),%r12
lea    0xec4(%rip),%rbx
mov    %rbx,%rcx
cmove  %r12,%rcx
lea    0xe98(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <ttyname@plt>
mov    %rax,%r15
mov    $0x1,%edi
call   1030 <isatty@plt>
test   %rax,%rax
mov    %rbx,%rcx
cmove  %r12,%rcx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1040 <printf@plt>
mov    $0x2,%edi
call   1050 <ttyname@plt>
mov    %rax,%r15
mov    $0x2,%edi
call   1030 <isatty@plt>
test   %rax,%rax
mov    %rbx,%rcx
cmove  %r12,%rcx
mov    %r14,%rdi
mov    $0x2,%esi
mov    %r15,%rdx
call   1040 <printf@plt>
mov    $0x3,%edi
call   1050 <ttyname@plt>
mov    %rax,%r15
mov    $0x3,%edi
call   1030 <isatty@plt>
test   %rax,%rax
cmove  %r12,%rbx
mov    %r14,%rdi
mov    $0x3,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"fd %d: ttyname:%s, %s a tty!\0A\00"
@.str.1 = [3 x i8] c"is\00"
@.str.2 = [6 x i8] c"isn't\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %7
7: ; preds = %20, %2
%8 = load i32, i32* %6
%9 = icmp sle i32 %8, 3
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = load i32, i32* %6
%12 = load i32, i32* %6
%13 = call i8* @ttyname(i32 %12)
%14 = load i32, i32* %6
%15 = call i64 @isatty(i32 %14)
%16 = icmp ne i64 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %13, i8* %18)
br label %20
20: ; preds = %10
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %7
23: ; preds = %7
ret i32 0
}

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