#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_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int errno;
int isatty(int /*<<< orphan*/);
int /*<<< orphan*/ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int main() {
  printf("read: %d\n", isatty(open("/read", O_RDONLY)));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("write: %d\n", isatty(open("/write", O_WRONLY)));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("all: %d\n", isatty(open("/all", O_RDONLY)));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("folder: %d\n", isatty(open("/folder", O_RDONLY)));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("file: %d\n", isatty(open("/file", O_RDONLY)));
  printf("errno: %d\n", errno);
  errno = 0;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xebb(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
mov    %eax,%esi
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e53(%rip),%rax
movl   $0x0,(%rax)
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    0xe8b(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
mov    %eax,%esi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e07(%rip),%rax
movl   $0x0,(%rax)
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
lea    0xe4f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
mov    %eax,%esi
lea    0xe31(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
lea    0xdff(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dbb(%rip),%rax
movl   $0x0,(%rax)
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
lea    0xe14(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
mov    %eax,%esi
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
lea    0xdb3(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d6f(%rip),%rax
movl   $0x0,(%rax)
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
lea    0xdda(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
mov    %eax,%esi
lea    0xdbb(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
lea    0xd67(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d23(%rip),%rax
movl   $0x0,(%rax)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2eac(%rip),%r15
mov    (%r15),%esi
lea    0xec4(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
lea    0xea7(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x2e71(%rip),%rbx
mov    (%rbx),%esi
lea    0xea0(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
movl   $0x0,(%rbx)
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
lea    0xe7a(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movl   $0x0,(%rbx)
mov    (%r15),%esi
lea    0xe74(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
lea    0xe58(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movl   $0x0,(%rbx)
mov    (%r15),%esi
lea    0xe51(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
lea    0xe32(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movl   $0x0,(%rbx)
mov    (%r15),%esi
lea    0xe2f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
lea    0xe12(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movl   $0x0,(%rbx)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"read: %d\0A\00"
@.str.1 = [6 x i8] c"/read\00"
@O_RDONLY = global i32 0
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [11 x i8] c"write: %d\0A\00"
@.str.4 = [7 x i8] c"/write\00"
@O_WRONLY = global i32 0
@.str.5 = [9 x i8] c"all: %d\0A\00"
@.str.6 = [5 x i8] c"/all\00"
@.str.7 = [12 x i8] c"folder: %d\0A\00"
@.str.8 = [8 x i8] c"/folder\00"
@.str.9 = [10 x i8] c"file: %d\0A\00"
@.str.10 = [6 x i8] c"/file\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @O_RDONLY
%3 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = call i32 @isatty(i32 %3)
%5 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @errno
%7 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %6)
store i32 0, i32* @errno
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%10 = call i32 @isatty(i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @errno
%13 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %12)
store i32 0, i32* @errno
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %14)
%16 = call i32 @isatty(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @errno
%19 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i32 0, i32* @errno
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %20)
%22 = call i32 @isatty(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %22)
%24 = load i32, i32* @errno
%25 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %24)
store i32 0, i32* @errno
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 %26)
%28 = call i32 @isatty(i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @errno
%31 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %30)
store i32 0, i32* @errno
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"read: %d\0A\00"
@.str.1 = [6 x i8] c"/read\00"
@O_RDONLY = global i32 0
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [11 x i8] c"write: %d\0A\00"
@.str.4 = [7 x i8] c"/write\00"
@O_WRONLY = global i32 0
@.str.5 = [9 x i8] c"all: %d\0A\00"
@.str.6 = [5 x i8] c"/all\00"
@.str.7 = [12 x i8] c"folder: %d\0A\00"
@.str.8 = [8 x i8] c"/folder\00"
@.str.9 = [10 x i8] c"file: %d\0A\00"
@.str.10 = [6 x i8] c"/file\00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%3 = tail call i32 @isatty(i32 %2)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @errno
%6 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %5)
store i32 0, i32* @errno
%7 = load i32, i32* @O_WRONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %7)
%9 = tail call i32 @isatty(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @errno
%12 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %11)
store i32 0, i32* @errno
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %13)
%15 = tail call i32 @isatty(i32 %14)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @errno
%18 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %17)
store i32 0, i32* @errno
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %19)
%21 = tail call i32 @isatty(i32 %20)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @errno
%24 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i32 0, i32* @errno
%25 = load i32, i32* @O_RDONLY
%26 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i32 %25)
%27 = tail call i32 @isatty(i32 %26)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @errno
%30 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %29)
store i32 0, i32* @errno
ret i32 0
}