#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 */
scalar_t__ EOF;
char *MALLOC(int);
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *readchars_file2(char *fn, long offset, int *nread) {
  FILE *fd = fopen(fn, "r");
  if (!fd) {
    fprintf(stderr, "readchars_file2: fn = %s\n", fn);
    fatal("open failed");
  }
  if (fseek(fd, offset + sizeof(float), SEEK_SET) == EOF)
    fatal("seek failed");
  char *result = MALLOC(*nread);
  int nbytesread = fread(result, 1, *nread, fd);
  if (nbytesread != *nread)
    fatal("fread failed");
  fclose(fd);
  return result;
}


x86 assembly (clang, -O0):
<readchars_file2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c8 <readchars_file2+0x58>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe59(%rip),%rdi
call   1090 <fatal@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    0x2dff(%rip),%rcx
cmp    (%rcx),%rax
jne    11fe <readchars_file2+0x8e>
lea    0xe2f(%rip),%rdi
call   1090 <fatal@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1060 <MALLOC@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
je     1243 <readchars_file2+0xd3>
lea    0xdf6(%rip),%rdi
call   1090 <fatal@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readchars_file2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11b9 <readchars_file2+0x49>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    %r12,%rdx
call   1050 <fprintf@plt>
lea    0xe68(%rip),%rdi
call   1090 <fatal@plt>
add    $0x4,%rbx
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <fseek@plt>
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%rax
jne    11e9 <readchars_file2+0x79>
lea    0xe44(%rip),%rdi
call   1090 <fatal@plt>
mov    (%r14),%edi
call   1060 <MALLOC@plt>
mov    %rax,%rbx
mov    (%r14),%edx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1030 <fread@plt>
cmp    (%r14),%eax
je     1218 <readchars_file2+0xa8>
lea    0xe21(%rip),%rdi
call   1090 <fatal@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"readchars_file2: fn = %s\0A\00"
@.str.2 = [12 x i8] c"open failed\00"
@SEEK_SET = global i32 0
@EOF = global i64 0
@.str.3 = [12 x i8] c"seek failed\00"
@.str.4 = [13 x i8] c"fread failed\00"
define i8* @readchars_file2(i8* %0, i64 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp ne i32* %12, null
br i1 %13, label %19, label %14
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %14, %3
%20 = load i32*, i32** %7
%21 = load i64, i64* %5
%22 = add i64 %21, 4
%23 = load i32, i32* @SEEK_SET
%24 = call i64 @fseek(i32* %20, i64 %22, i32 %23)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %19
%30 = load i32*, i32** %6
%31 = load i32, i32* %30
%32 = call i8* @MALLOC(i32 %31)
store i8* %32, i8** %8
%33 = load i8*, i8** %8
%34 = load i32*, i32** %6
%35 = load i32, i32* %34
%36 = load i32*, i32** %7
%37 = call i32 @fread(i8* %33, i32 1, i32 %35, i32* %36)
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
%41 = icmp ne i32 %38, %40
br i1 %41, label %42, label %44
42: ; preds = %29
%43 = call i32 @fatal(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %29
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
%47 = load i8*, i8** %8
ret i8* %47
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"readchars_file2: fn = %s\0A\00"
@.str.2 = [12 x i8] c"open failed\00"
@SEEK_SET = global i32 0
@EOF = global i64 0
@.str.3 = [12 x i8] c"seek failed\00"
@.str.4 = [13 x i8] c"fread failed\00"
define i8* @readchars_file2(i8* %0, i64 %1, i32* nocapture %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %6, %3
%11 = add i64 %1, 4
%12 = load i32, i32* @SEEK_SET
%13 = tail call i64 @fseek(i32* %4, i64 %11, i32 %12)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @fatal(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = load i32, i32* %2
%20 = tail call i8* @MALLOC(i32 %19)
%21 = load i32, i32* %2
%22 = tail call i32 @fread(i8* %20, i32 1, i32 %21, i32* %4)
%23 = load i32, i32* %2
%24 = icmp eq i32 %22, %23
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = tail call i32 @fatal(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %18
%28 = tail call i32 @fclose(i32* %4)
ret i8* %20
}