#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(unsigned char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  assert(argc >= 2);
  FILE *pf_ro = fopen(argv[1], "r");
  if (pf_ro == NULL) {
    perror("fopen failed");
    goto err_fopen;
  }
  unsigned char rbuf[4096] = {0};
  fseek(pf_ro, 100, SEEK_SET);
  size_t n;
  while ((n = fread(rbuf, 1, 4096, pf_ro)) != 0) {
    fwrite(rbuf, 1, n, stdout);
  }
  fclose(pf_ro);
  return 0;
err_fopen:
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11de <main+0x5e>
lea    0xe2e(%rip),%rdi
call   1090 <perror@plt>
jmp    126e <main+0xee>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1070 <fseek@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
je     1259 <main+0xd9>
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rdx
mov    0x2d90(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
jmp    1208 <main+0x88>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1275 <main+0xf5>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
setge  %al
mov    %eax,%edi
call   1060 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xe56(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1256 <main+0xd6>
mov    %rax,%rbx
mov    %rsp,%rbp
xor    %r14d,%r14d
mov    $0x1000,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1070 <fseek@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     123d <main+0xbd>
mov    0x2dd1(%rip),%r15
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
mov    (%r15),%ecx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   10a0 <fwrite@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    1210 <main+0x90>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14d,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xda5(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1245 <main+0xc5>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"fopen failed\00"
@SEEK_SET = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [4096 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 2
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %39
21: ; preds = %2
%22 = bitcast [4096 x i8]* %7 to i8*
%23 = load i32*, i32** %6
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %23, i32 100, i32 %24)
br label %26
26: ; preds = %31, %21
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%28 = load i32*, i32** %6
%29 = call i64 @fread(i8* %27, i32 1, i32 4096, i32* %28)
store i64 %29, i64* %8
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%33 = load i64, i64* %8
%34 = load i32, i32* @stdout
%35 = call i32 @fwrite(i8* %32, i32 1, i64 %33, i32 %34)
br label %26
36: ; preds = %26
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
store i32 0, i32* %3
br label %40
39: ; preds = %19
store i32 -1, i32* %3
br label %40
40: ; preds = %39, %36
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"fopen failed\00"
@SEEK_SET = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = icmp sgt i32 %0, 1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %27
13: ; preds = %2
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %9, i32 100, i32 %15)
%17 = call i64 @fread(i8* %14, i32 1, i32 4096, i32* %9)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %13, %19
%20 = phi i64 [ %23, %19 ], [ %17, %13 ]
%21 = load i32, i32* @stdout
%22 = call i32 @fwrite(i8* %14, i32 1, i64 %20, i32 %21)
%23 = call i64 @fread(i8* %14, i32 1, i32 4096, i32* %9)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %19
25: ; preds = %19, %13
%26 = call i32 @fclose(i32* %9)
br label %27
27: ; preds = %11, %25
%28 = phi i32 [ -1, %11 ], [ 0, %25 ]
ret i32 %28
}