#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ isatty(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd;
  printf("Hello\n");
  write(1, "world\n", 6);
  fd = open("/dev/tty", O_WRONLY);
  if (fd == -1) {
    printf("error : %m\n");
    exit(1);
  }
  if (isatty(1)) {
    write(1, "noreadir\n", 9);
  } else {
    write(1, "readir\n", 6);
  }
  write(fd, "killer", sizeof("killer") + 1);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
lea    0xe80(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c9 <main+0x69>
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
cmp    $0x0,%rax
je     11f8 <main+0x98>
mov    $0x1,%edi
lea    0xe3a(%rip),%rsi
mov    $0x9,%edx
call   1040 <write@plt>
jmp    120e <main+0xae>
mov    $0x1,%edi
lea    0xe21(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe15(%rip),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb5(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7c(%rip),%rsi
mov    $0x1,%edi
mov    $0x6,%edx
call   1050 <write@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1205 <main+0x95>
mov    %eax,%ebx
mov    $0x1,%edi
call   1040 <isatty@plt>
test   %rax,%rax
je     11d1 <main+0x61>
lea    0xe57(%rip),%rsi
mov    $0x1,%edi
mov    $0x9,%edx
jmp    11e2 <main+0x72>
lea    0xe46(%rip),%rsi
mov    $0x1,%edi
mov    $0x6,%edx
call   1050 <write@plt>
lea    0xe38(%rip),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1050 <write@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe04(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"Hello\0A\00"
@.str.1 = [7 x i8] c"world\0A\00"
@.str.2 = [9 x i8] c"/dev/tty\00"
@O_WRONLY = global i32 0
@.str.3 = [12 x i8] c"error : %m\0A\00"
@.str.4 = [10 x i8] c"noreadir\0A\00"
@.str.5 = [8 x i8] c"readir\0A\00"
@.str.6 = [7 x i8] c"killer\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @write(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i64 @isatty(i32 1)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @write(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 9)
br label %19
17: ; preds = %12
%18 = call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 6)
br label %19
19: ; preds = %17, %15
%20 = load i32, i32* %2
%21 = call i32 @write(i32 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 8)
%22 = load i32, i32* %2
%23 = call i32 @close(i32 %22)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"world\0A\00"
@.str.2 = [9 x i8] c"/dev/tty\00"
@O_WRONLY = global i32 0
@.str.3 = [12 x i8] c"error : %m\0A\00"
@.str.4 = [10 x i8] c"noreadir\0A\00"
@.str.5 = [8 x i8] c"readir\0A\00"
@.str.6 = [7 x i8] c"killer\00"
@str = [6 x i8] c"Hello\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i64 @isatty(i32 1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 9)
br label %16
14: ; preds = %9
%15 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 6)
br label %16
16: ; preds = %14, %12
%17 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 8)
%18 = tail call i32 @close(i32 %4)
ret i32 0
}