#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 header {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
struct header *spec_parser_string(char *, int);
int /*<<< orphan*/ xlog(int, char *, char const *);
struct header *spec_parser_file(const char *filename) {
  FILE *fp;
  int size;
  char *s;
  struct header *h;
  fp = fopen(filename, "r");
  if (!fp) {
    xlog(32, "Unable to open file: %s.\n", filename);
    return NULL;
  }
  fseek(fp, 0, SEEK_END);
  size = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  s = malloc(size + 1);
  fread(s, size, 1, fp);
  s[size] = 0;
  fclose(fp);
  h = spec_parser_string(s, size);
  free(s);
  return h;
}


x86 assembly (clang, -O0):
<spec_parser_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11dd <spec_parser_file+0x4d>
mov    -0x10(%rbp),%rdx
mov    $0x20,%edi
lea    0xe37(%rip),%rsi
call   1060 <xlog@plt>
movq   $0x0,-0x8(%rbp)
jmp    126b <spec_parser_file+0xdb>
mov    -0x18(%rbp),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <spec_parser_string@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spec_parser_file>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe61(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1227 <spec_parser_file+0x97>
mov    %rax,%rbx
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %eax,%r14d
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
lea    0x1(%r14),%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movslq %r14d,%r14
movb   $0x0,(%r15,%r14,1)
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <spec_parser_string@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    123d <spec_parser_file+0xad>
lea    0xdd4(%rip),%rsi
mov    $0x20,%edi
mov    %r14,%rdx
call   1060 <xlog@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.header = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"Unable to open file: %s.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define %struct.header* @spec_parser_file(i8* %0) {
%2 = alloca %struct.header*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.header*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @xlog(i32 32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store %struct.header* null, %struct.header** %2
br label %43
15: ; preds = %1
%16 = load i32*, i32** %4
%17 = load i32, i32* @SEEK_END
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = load i32*, i32** %4
%20 = call i32 @ftell(i32* %19)
store i32 %20, i32* %5
%21 = load i32*, i32** %4
%22 = load i32, i32* @SEEK_SET
%23 = call i32 @fseek(i32* %21, i32 0, i32 %22)
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = load i32, i32* %5
%29 = load i32*, i32** %4
%30 = call i32 @fread(i8* %27, i32 %28, i32 1, i32* %29)
%31 = load i8*, i8** %6
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = load i32*, i32** %4
%36 = call i32 @fclose(i32* %35)
%37 = load i8*, i8** %6
%38 = load i32, i32* %5
%39 = call %struct.header* @spec_parser_string(i8* %37, i32 %38)
store %struct.header* %39, %struct.header** %7
%40 = load i8*, i8** %6
%41 = call i32 @free(i8* %40)
%42 = load %struct.header*, %struct.header** %7
store %struct.header* %42, %struct.header** %2
br label %43
43: ; preds = %15, %12
%44 = load %struct.header*, %struct.header** %2
ret %struct.header* %44
}

LLVM IR (-O2):
%struct.header = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"Unable to open file: %s.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define %struct.header* @spec_parser_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @xlog(i32 32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
6: ; preds = %1
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %2, i32 0, i32 %7)
%9 = tail call i32 @ftell(i32* %2)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %2, i32 0, i32 %10)
%12 = add nsw i32 %9, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = tail call i32 @fread(i8* %13, i32 %9, i32 1, i32* %2)
%15 = sext i32 %9 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 0, i8* %16
%17 = tail call i32 @fclose(i32* %2)
%18 = tail call %struct.header* @spec_parser_string(i8* %13, i32 %9)
%19 = tail call i32 @free(i8* %13)
br label %20
20: ; preds = %6, %4
%21 = phi %struct.header* [ %18, %6 ], [ null, %4 ]
ret %struct.header* %21
}