#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*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
scalar_t__ strlen(char *);
int /*<<< orphan*/ utf8_parse(char const *, unsigned int);
int load_file(FILE *fp) {
  char *buffer = NULL;
  size_t szbuf = 0;
  szbuf = 10000;
  buffer = (char *)malloc(szbuf);
  if (NULL == buffer)
    return -1;
  while (getline(&buffer, &szbuf, fp) > 0)
    utf8_parse((const char *)buffer, (unsigned int)strlen((char *)buffer));
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x2710,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    1199 <load_file+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ea <load_file+0x9a>
jmp    119e <load_file+0x4e>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0x0,%rax
jle    11da <load_file+0x8a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1060 <utf8_parse@plt>
jmp    119e <load_file+0x4e>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
movq   $0x2710,0x10(%rsp)
mov    $0x2710,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     11d8 <load_file+0x88>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r12,%rdx
call   1070 <getline@plt>
test   %rax,%rax
jle    11ca <load_file+0x7a>
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
nopl   0x0(%rax)
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <utf8_parse@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <getline@plt>
test   %rax,%rax
jg     11a0 <load_file+0x50>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11dd <load_file+0x8d>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @load_file(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
store i32* %0, i32** %3
store i8* null, i8** %4
store i64 0, i64* %5
store i64 10000, i64* %5
%6 = load i64, i64* %5
%7 = call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp eq i8* null, %9
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %26
12: ; preds = %1
br label %13
13: ; preds = %17, %12
%14 = load i32*, i32** %3
%15 = call i64 @getline(i8** %4, i64* %5, i32* %14)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i8*, i8** %4
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
%22 = call i32 @utf8_parse(i8* %18, i32 %21)
br label %13
23: ; preds = %13
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
store i32 0, i32* %2
br label %26
26: ; preds = %23, %11
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @load_file(i32* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
%5 = bitcast i64* %3 to i8*
store i64 10000, i64* %3
%6 = tail call i64 @malloc(i64 10000)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %2
%8 = icmp eq i64 %6, 0
br i1 %8, label %22, label %9
9: ; preds = %1
%10 = call i64 @getline(i8** %2, i64* %3, i32* %0)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9, %12
%13 = load i8*, i8** %2
%14 = call i64 @strlen(i8* dereferenceable(1) %13)
%15 = trunc i64 %14 to i32
%16 = call i32 @utf8_parse(i8* %13, i32 %15)
%17 = call i64 @getline(i8** %2, i64* %3, i32* %0)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %12, label %19
19: ; preds = %12, %9
%20 = load i8*, i8** %2
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %1, %19
%23 = phi i32 [ 0, %19 ], [ -1, %1 ]
ret i32 %23
}