#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 SVGPath {
  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*/ *);
scalar_t__ malloc(int);
struct SVGPath *svgParse(char *);
struct SVGPath *svgParseFromFile(const char *filename) {
  FILE *fp;
  int size;
  char *data;
  struct SVGPath *plist;
  fp = fopen(filename, "rb");
  if (!fp)
    return 0;
  fseek(fp, 0, SEEK_END);
  size = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  data = (char *)malloc(size + 1);
  fread(data, size, 1, fp);
  data[size] = '\0';
  fclose(fp);
  plist = svgParse(data);
  free(data);
  return plist;
}


x86 assembly (clang, -O0):
<svgParseFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b8 <svgParseFromFile+0x38>
movq   $0x0,-0x8(%rbp)
jmp    1243 <svgParseFromFile+0xc3>
mov    -0x18(%rbp),%rdi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1080 <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
call   1060 <svgParse@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):
<svgParseFromFile>:
push   %r15
push   %r14
push   %rbx
lea    0xe74(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1211 <svgParseFromFile+0x91>
mov    %rax,%rbx
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%r14d
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0x1(%r14),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
movslq %r14d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1060 <svgParse@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    1213 <svgParseFromFile+0x93>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.SVGPath = type { i32 }
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define %struct.SVGPath* @svgParseFromFile(i8* %0) {
%2 = alloca %struct.SVGPath*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.SVGPath*
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 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 %13, label %12
12: ; preds = %1
store %struct.SVGPath* null, %struct.SVGPath** %2
br label %41
13: ; preds = %1
%14 = load i32*, i32** %4
%15 = load i32, i32* @SEEK_END
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = load i32*, i32** %4
%18 = call i32 @ftell(i32* %17)
store i32 %18, i32* %5
%19 = load i32*, i32** %4
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = load i32, i32* %5
%28 = load i32*, i32** %4
%29 = call i32 @fread(i8* %26, i32 %27, i32 1, i32* %28)
%30 = load i8*, i8** %6
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
%34 = load i32*, i32** %4
%35 = call i32 @fclose(i32* %34)
%36 = load i8*, i8** %6
%37 = call %struct.SVGPath* @svgParse(i8* %36)
store %struct.SVGPath* %37, %struct.SVGPath** %7
%38 = load i8*, i8** %6
%39 = call i32 @free(i8* %38)
%40 = load %struct.SVGPath*, %struct.SVGPath** %7
store %struct.SVGPath* %40, %struct.SVGPath** %2
br label %41
41: ; preds = %13, %12
%42 = load %struct.SVGPath*, %struct.SVGPath** %2
ret %struct.SVGPath* %42
}

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