#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 */
typedef scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, scalar_t__);
scalar_t__ read(int, char **, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char buffer[1024];
  int fd = open("/tmp/usfsal/tmp/test.tar.gz#/test/testfile00", O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "Unable to open %s: %s\n",
            "/tmp/usfsal/tmp/test.tar.gz#/test/testfile00", strerror(errno));
    exit(1);
  }
  ssize_t bytes_read = read(fd, &buffer, 1024);
  if (bytes_read < 0) {
    fprintf(stderr, "Unable to read %s: %s\n",
            "/tmp/usfsal/tmp/test.tar.gz#/test/testfile00", strerror(errno));
    exit(1);
  }
  printf("BYTES READ: %ld\n", bytes_read);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0xffffffff,-0x414(%rbp)
jne    11f4 <main+0x84>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x424(%rbp),%edi
mov    %rax,%rcx
lea    0xe4f(%rip),%rsi
lea    0xe1b(%rip),%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
jge    1263 <main+0xf3>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x428(%rbp),%edi
mov    %rax,%rcx
lea    0xdf7(%rip),%rsi
lea    0xdac(%rip),%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x420(%rbp),%rsi
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
mov    -0x414(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x59>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
js     11e9 <main+0x79>
lea    0xeac(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret
mov    0x2e08(%rip),%rax
mov    (%rax),%ebx
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe46(%rip),%rsi
jmp    1207 <main+0x97>
mov    0x2de8(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe3d(%rip),%rsi
lea    0xdf2(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"/tmp/usfsal/tmp/test.tar.gz#/test/testfile00\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"Unable to open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"Unable to read %s: %s\0A\00"
@.str.3 = [17 x i8] c"BYTES READ: %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* %7
%21 = bitcast [1024 x i8]* %6 to i8**
%22 = call i64 @read(i32 %20, i8** %21, i32 1024)
store i64 %22, i64* %8
%23 = load i64, i64* %8
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %19
%32 = load i64, i64* %8
%33 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %32)
%34 = load i32, i32* %7
%35 = call i32 @close(i32 %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [45 x i8] c"/tmp/usfsal/tmp/test.tar.gz#/test/testfile00\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"Unable to open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"Unable to read %s: %s\0A\00"
@.str.3 = [17 x i8] c"BYTES READ: %ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = bitcast [1024 x i8]* %3 to i8**
%16 = call i64 @read(i32 %6, i8** %15, i32 1024)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %16)
%26 = tail call i32 @close(i32 %6)
ret i32 0
}