#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*/ SEEK_CUR;
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
char getc(int /*<<< orphan*/ *);
char *malloc(int);
int loadstr(FILE *file, char **buf) {
  int filenameLength = 0, index = 0;
  char *name;
  char bit;
  while ((bit = getc(file) != '\0')) {
    filenameLength++;
    if (bit == 0) {
    }
  }
  name = malloc(sizeof(char) * (filenameLength + 1));
  fseek(file, -(filenameLength + 1), SEEK_CUR);
  for (index = 0; index < filenameLength + 1; index++) {
    name[index] = getc(file);
  }
  (*buf) = name;
  return 0;
}


x86 assembly (clang, -O0):
<loadstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
movsbl %al,%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %al,-0x21(%rbp)
cmp    $0x0,%al
je     1190 <loadstr+0x60>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    118b <loadstr+0x5b>
jmp    118b <loadstr+0x5b>
jmp    114e <loadstr+0x1e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
xor    %esi,%esi
sub    %eax,%esi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11ff <loadstr+0xcf>
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ca <loadstr+0x9a>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1050 <getc@plt>
add    $0x1,%ebp
test   %al,%al
jne    1140 <loadstr+0x10>
mov    %ebp,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
mov    %ebp,%esi
neg    %esi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1040 <fseek@plt>
test   %ebp,%ebp
jle    1195 <loadstr+0x65>
mov    %ebp,%r12d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <getc@plt>
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1180 <loadstr+0x50>
mov    %r15,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define i32 @loadstr(i32* %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
store i32* %0, i32** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %24, %2
%10 = load i32*, i32** %3
%11 = call signext i8 @getc(i32* %10)
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i32
%15 = trunc i32 %14 to i8
store i8 %15, i8* %8
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %9
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = load i8, i8* %8
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %24
24: ; preds = %23, %17
br label %9
25: ; preds = %9
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = mul i64 1, %28
%30 = trunc i64 %29 to i32
%31 = call i8* @malloc(i32 %30)
store i8* %31, i8** %7
%32 = load i32*, i32** %3
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
%35 = sub nsw i32 0, %34
%36 = load i32, i32* @SEEK_CUR
%37 = call i32 @fseek(i32* %32, i32 %35, i32 %36)
store i32 0, i32* %6
br label %38
38: ; preds = %50, %25
%39 = load i32, i32* %6
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
%42 = icmp slt i32 %39, %41
br i1 %42, label %43, label %53
43: ; preds = %38
%44 = load i32*, i32** %3
%45 = call signext i8 @getc(i32* %44)
%46 = load i8*, i8** %7
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 %45, i8* %49
br label %50
50: ; preds = %43
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %38
53: ; preds = %38
%54 = load i8*, i8** %7
%55 = load i8**, i8*** %4
store i8* %54, i8** %55
ret i32 0
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define i32 @loadstr(i32* nocapture %0, i8** nocapture writeonly %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 1, %2 ], [ %7, %3 ]
%5 = tail call signext i8 @getc(i32* %0)
%6 = icmp eq i8 %5, 0
%7 = add i32 %4, 1
br i1 %6, label %8, label %3
8: ; preds = %3
%9 = tail call i8* @malloc(i32 %4)
%10 = sub nsw i32 0, %4
%11 = load i32, i32* @SEEK_CUR
%12 = tail call i32 @fseek(i32* %0, i32 %10, i32 %11)
%13 = icmp sgt i32 %4, 0
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = zext i32 %4 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %20, %16 ]
%18 = tail call signext i8 @getc(i32* %0)
%19 = getelementptr inbounds i8, i8* %9, i64 %17
store i8 %18, i8* %19
%20 = add nuw nsw i64 %17, 1
%21 = icmp eq i64 %20, %15
br i1 %21, label %22, label %16
22: ; preds = %16, %8
store i8* %9, i8** %1
ret i32 0
}