#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 */
struct ExcelData {
  int dummy;
};
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
struct ExcelData *excel_open(char *, scalar_t__, int);
int /*<<< orphan*/ free(char *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(scalar_t__);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, scalar_t__);
struct ExcelData *excel_open_file(char *filename, int strip_strings) {
  int fd;
  off_t size;
  char *buffer;
  struct ExcelData *result;
  fd = open(filename, O_RDONLY);
  if (fd < 0)
    return NULL;
  size = lseek(fd, 0, SEEK_END);
  lseek(fd, 0, SEEK_SET);
  buffer = malloc(size);
  if (buffer == NULL) {
    close(fd);
    return NULL;
  }
  if (read(fd, buffer, size) != size) {
    close(fd);
    free(buffer);
    return NULL;
  }
  result = excel_open(buffer, size, strip_strings);
  return result;
}


x86 assembly (clang, -O0):
<excel_open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ab <excel_open_file+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    1256 <excel_open_file+0xe6>
mov    -0x18(%rbp),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1202 <excel_open_file+0x92>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    1256 <excel_open_file+0xe6>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <read@plt>
cmp    -0x20(%rbp),%rax
je     123a <excel_open_file+0xca>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1256 <excel_open_file+0xe6>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <excel_open@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<excel_open_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     1207 <excel_open_file+0x97>
mov    %eax,%ebp
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %rax,%r15
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %r15,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     11ef <excel_open_file+0x7f>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %rax,%rsi
mov    %r15,%rdx
call   1070 <read@plt>
cmp    %r15,%rax
jne    11f8 <excel_open_file+0x88>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <excel_open@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    1207 <excel_open_file+0x97>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ExcelData = type { i32 }
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define %struct.ExcelData* @excel_open_file(i8* %0, i32 %1) {
%3 = alloca %struct.ExcelData*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca %struct.ExcelData*
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i8*, i8** %4
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store %struct.ExcelData* null, %struct.ExcelData** %3
br label %48
16: ; preds = %2
%17 = load i32, i32* %6
%18 = load i32, i32* @SEEK_END
%19 = call i64 @lseek(i32 %17, i32 0, i32 %18)
store i64 %19, i64* %7
%20 = load i32, i32* %6
%21 = load i32, i32* @SEEK_SET
%22 = call i64 @lseek(i32 %20, i32 0, i32 %21)
%23 = load i64, i64* %7
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %8
%25 = load i8*, i8** %8
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %16
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
store %struct.ExcelData* null, %struct.ExcelData** %3
br label %48
30: ; preds = %16
%31 = load i32, i32* %6
%32 = load i8*, i8** %8
%33 = load i64, i64* %7
%34 = call i64 @read(i32 %31, i8* %32, i64 %33)
%35 = load i64, i64* %7
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %30
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
%40 = load i8*, i8** %8
%41 = call i32 @free(i8* %40)
store %struct.ExcelData* null, %struct.ExcelData** %3
br label %48
42: ; preds = %30
%43 = load i8*, i8** %8
%44 = load i64, i64* %7
%45 = load i32, i32* %5
%46 = call %struct.ExcelData* @excel_open(i8* %43, i64 %44, i32 %45)
store %struct.ExcelData* %46, %struct.ExcelData** %9
%47 = load %struct.ExcelData*, %struct.ExcelData** %9
store %struct.ExcelData* %47, %struct.ExcelData** %3
br label %48
48: ; preds = %42, %37, %27, %15
%49 = load %struct.ExcelData*, %struct.ExcelData** %3
ret %struct.ExcelData* %49
}

LLVM IR (-O2):
%struct.ExcelData = type { i32 }
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define %struct.ExcelData* @excel_open_file(i8* nocapture %0, i32 %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = load i32, i32* @SEEK_END
%8 = tail call i64 @lseek(i32 %4, i32 0, i32 %7)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i64 @lseek(i32 %4, i32 0, i32 %9)
%11 = tail call i8* @malloc(i64 %8)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i32 @close(i32 %4)
br label %23
15: ; preds = %6
%16 = tail call i64 @read(i32 %4, i8* %11, i64 %8)
%17 = icmp eq i64 %16, %8
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = tail call i32 @close(i32 %4)
%20 = tail call i32 @free(i8* %11)
br label %23
21: ; preds = %15
%22 = tail call %struct.ExcelData* @excel_open(i8* %11, i64 %8, i32 %1)
br label %23
23: ; preds = %2, %21, %18, %13
%24 = phi %struct.ExcelData* [ null, %13 ], [ null, %18 ], [ %22, %21 ], [ null, %2 ]
ret %struct.ExcelData* %24
}