#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_SET;
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *realloc(char *, int);
int strlen(char *);
int /*<<< orphan*/ sys_fread(char *, int, int, int /*<<< orphan*/ *);
char *_dbx_read_string(FILE *file, int offset) {
  char c[256] = {};
  char *s = NULL;
  int n = 0;
  int l = 0;
  fseek(file, offset, SEEK_SET);
  do {
    sys_fread(c, 1, 255, file);
    l = strlen(c);
    s = realloc(s, n + l + 1);
    memcpy(s + n, c, l);
    n += l;
    s[n] = '\0';
  } while (l == 255);
  return s;
}


x86 assembly (clang, -O0):
<_dbx_read_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
movq   $0x0,-0x118(%rbp)
movl   $0x0,-0x11c(%rbp)
movl   $0x0,-0x120(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0xff,%edx
call   1030 <sys_fread@plt>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x120(%rbp)
mov    -0x118(%rbp),%rdi
mov    -0x11c(%rbp),%esi
add    -0x120(%rbp),%esi
add    $0x1,%esi
call   1080 <realloc@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
movslq -0x11c(%rbp),%rax
add    %rax,%rdi
lea    -0x110(%rbp),%rsi
mov    -0x120(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x120(%rbp),%eax
add    -0x11c(%rbp),%eax
mov    %eax,-0x11c(%rbp)
mov    -0x118(%rbp),%rax
movslq -0x11c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0xff,-0x120(%rbp)
je     11b9 <_dbx_read_string+0x59>
mov    -0x118(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dbx_read_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
xor    %r12d,%r12d
mov    %rsp,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0xff,%edx
mov    %r14,%rcx
call   1030 <sys_fread@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
lea    (%rbx,%r13,1),%ebp
lea    (%rbx,%r13,1),%esi
add    $0x1,%esi
mov    %r12,%rdi
call   1070 <realloc@plt>
mov    %rax,%r12
movslq %ebx,%rdi
add    %rax,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r12,%rax,1)
mov    %ebp,%ebx
cmp    $0xff,%r13d
je     11f0 <_dbx_read_string+0xa0>
mov    %r12,%rax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i8* @_dbx_read_string(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = bitcast [256 x i8]* %5 to i8*
store i8* null, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load i32*, i32** %3
%11 = load i32, i32* %4
%12 = load i32, i32* @SEEK_SET
%13 = call i32 @fseek(i32* %10, i32 %11, i32 %12)
br label %14
14: ; preds = %40, %2
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i32 @sys_fread(i8* %15, i32 1, i32 255, i32* %16)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %8
%20 = load i8*, i8** %6
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = add nsw i32 %21, %22
%24 = add nsw i32 %23, 1
%25 = call i8* @realloc(i8* %20, i32 %24)
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%31 = load i32, i32* %8
%32 = call i32 @memcpy(i8* %29, i8* %30, i32 %31)
%33 = load i32, i32* %8
%34 = load i32, i32* %7
%35 = add nsw i32 %34, %33
store i32 %35, i32* %7
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %14
%41 = load i32, i32* %8
%42 = icmp eq i32 %41, 255
br i1 %42, label %14, label %43
43: ; preds = %40
%44 = load i8*, i8** %6
ret i8* %44
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i8* @_dbx_read_string(i32* %0, i32 %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i32 %1, i32 %5)
br label %7
7: ; preds = %7, %2
%8 = phi i8* [ null, %2 ], [ %14, %7 ]
%9 = phi i32 [ 0, %2 ], [ %12, %7 ]
%10 = call i32 @sys_fread(i8* %4, i32 1, i32 255, i32* %0)
%11 = call i32 @strlen(i8* %4)
%12 = add nsw i32 %11, %9
%13 = add nsw i32 %12, 1
%14 = call i8* @realloc(i8* %8, i32 %13)
%15 = sext i32 %9 to i64
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = call i32 @memcpy(i8* %16, i8* %4, i32 %11)
%18 = sext i32 %12 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
store i8 0, i8* %19
%20 = icmp eq i32 %11, 255
br i1 %20, label %7, label %21
21: ; preds = %7
ret i8* %14
}