#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ isatty(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ replay(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *ttyname(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  if (!isatty(fileno(stdout))) {
    printf("is not tty\n");
    return 1;
  }
  char *mytty = ttyname(fileno(stdout));
  printf("Sending output to: %s\n", mytty);
  char *filename;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  filename = argv[1];
  replay(filename, mytty);
  printf("End replay\n");
  usleep(5000);
  exit(EXIT_SUCCESS);
  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    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
jne    11cd <main+0x4d>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
call   1070 <ttyname@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
je     122c <main+0xac>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0a(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <replay@plt>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1388,%edi
call   10a0 <usleep@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2e2d(%rip),%rbx
mov    (%rbx),%edi
call   1070 <fileno@plt>
mov    %eax,%edi
call   1040 <isatty@plt>
test   %eax,%eax
jne    11d1 <main+0x41>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%edi
call   1070 <fileno@plt>
mov    %eax,%edi
call   1080 <ttyname@plt>
mov    %rax,%r14
lea    0xe17(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%ebp
jne    1228 <main+0x98>
mov    0x8(%r15),%rdi
mov    %r14,%rsi
call   1090 <replay@plt>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1388,%edi
call   10b0 <usleep@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xddc(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [12 x i8] c"is not tty\0A\00"
@.str.1 = [23 x i8] c"Sending output to: %s\0A\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Usage: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [12 x i8] c"End replay\0A\00"
@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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @stdout
%9 = call i32 @fileno(i32 %8)
%10 = call i32 @isatty(i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
ret i32 1
14: ; preds = %2
%15 = load i32, i32* @stdout
%16 = call i32 @fileno(i32 %15)
%17 = call i8* @ttyname(i32 %16)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 2
br i1 %21, label %22, label %30
22: ; preds = %14
%23 = load i32, i32* @stderr
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %14
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = load i8*, i8** %6
%36 = call i32 @replay(i8* %34, i8* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 @usleep(i32 5000)
%39 = load i32, i32* @EXIT_SUCCESS
%40 = call i32 @exit(i32 %39)
unreachable
}

LLVM IR (-O2):
@stdout = global i32 0
@.str.1 = [23 x i8] c"Sending output to: %s\0A\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"Usage: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [11 x i8] c"is not tty\00"
@str.4 = [11 x i8] c"End replay\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 @fileno(i32 %3)
%5 = tail call i32 @isatty(i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
ret i32 1
9: ; preds = %2
%10 = load i32, i32* @stdout
%11 = tail call i32 @fileno(i32 %10)
%12 = tail call i8* @ttyname(i32 %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = icmp eq i32 %0, 2
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %9
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32 @replay(i8* %23, i8* %12)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.4, i64 0, i64 0))
%26 = tail call i32 @usleep(i32 5000)
%27 = load i32, i32* @EXIT_SUCCESS
%28 = tail call i32 @exit(i32 %27)
unreachable
}