#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*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int doin(char *s) {
  int fd;
  char buffer[1024 * 128];
  if ((fd = open(s, O_RDONLY)) < 0) {
    fprintf(stderr, "fopen: %s %s\n", strerror(errno), s);
    return (-1);
  }
  while (read(fd, buffer, 1024 * 128) != 0)
    ;
  (void)close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<doin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20030,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11bf <doin+0x6f>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20024(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20024(%rbp),%edi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
lea    0xe52(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <doin+0xa6>
jmp    11c4 <doin+0x74>
mov    -0x14(%rbp),%edi
lea    -0x20020(%rbp),%rsi
mov    $0x20000,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
je     11e7 <doin+0x97>
jmp    11c4 <doin+0x74>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doin>:
push   %rbp
push   %rbx
sub    $0x20008,%rsp
mov    %rdi,%rbx
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     119f <doin+0x4f>
mov    %eax,%ebp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x20000,%edx
call   1040 <read@plt>
test   %rax,%rax
jne    1180 <doin+0x30>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %eax,%eax
jmp    11cf <doin+0x7f>
mov    0x2e32(%rip),%rax
mov    (%rax),%ebp
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe43(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x20008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"fopen: %s %s\0A\00"
@errno = global i32 0
define i32 @doin(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [131072 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = load i8*, i8** %3
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14)
store i32 -1, i32* %2
br label %26
16: ; preds = %1
br label %17
17: ; preds = %22, %16
%18 = load i32, i32* %4
%19 = getelementptr inbounds [131072 x i8], [131072 x i8]* %5, i64 0, i64 0
%20 = call i64 @read(i32 %18, i8* %19, i32 131072)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %17
23: ; preds = %17
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
store i32 0, i32* %2
br label %26
26: ; preds = %23, %10
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"fopen: %s %s\0A\00"
@errno = global i32 0
define i32 @doin(i8* %0) {
%2 = alloca [131072 x i8]
%3 = getelementptr inbounds [131072 x i8], [131072 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %0)
br label %17
12: ; preds = %1, %12
%13 = call i64 @read(i32 %5, i8* %3, i32 131072)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %12
15: ; preds = %12
%16 = tail call i32 @close(i32 %5)
br label %17
17: ; preds = %15, %7
%18 = phi i32 [ -1, %7 ], [ 0, %15 ]
ret i32 %18
}