#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;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ int_cond_fatal(int /*<<< orphan*/, int /*<<< orphan*/ *,
                                  char *);
scalar_t__ our_malloc(int);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ setup_error(char *, int);
int strlen(char *);
int zgetline(FILE *f, char **buffer, int size) {
  char *b;
  char c;
  int new_size;
  int done = 0;
  b = *buffer;
  new_size = size;
  while (!done) {
    fgets(b, new_size, f);
    if (strlen(*buffer) < new_size - 1) {
      done = 1;
    } else {
      fseek(f, -1, SEEK_CUR);
      c = fgetc(f);
      if (c == '\n') {
        done = 1;
      } else {
        b = &(*buffer)[new_size - 1];
        new_size += size;
        if (*buffer != NULL) {
          *buffer = (char *)realloc(*buffer, new_size);
        } else {
          *buffer = (char *)our_malloc(new_size);
        }
        setup_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/tangentforks/zpl/refs/"
                    "heads/master/comp/main/runpass.c",
                    61);
        int_cond_fatal((*buffer != NULL), NULL, "Realloc failed in zgetline()");
      }
    }
  }
  return new_size;
}


x86 assembly (clang, -O0):
<zgetline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x2c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c1 <zgetline+0x41>
jmp    12cc <zgetline+0x14c>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11f7 <zgetline+0x77>
movl   $0x1,-0x2c(%rbp)
jmp    12c7 <zgetline+0x147>
mov    -0x8(%rbp),%rdi
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1070 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    1233 <zgetline+0xb3>
movl   $0x1,-0x2c(%rbp)
jmp    12c2 <zgetline+0x142>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     127f <zgetline+0xff>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%esi
call   1080 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1291 <zgetline+0x111>
mov    -0x28(%rbp),%edi
call   1090 <our_malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    0xd68(%rip),%rdi
mov    $0x3d,%esi
call   10a0 <setup_error@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    0xdd4(%rip),%rdx
call   1060 <int_cond_fatal@plt>
jmp    12c7 <zgetline+0x147>
jmp    11ab <zgetline+0x2b>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zgetline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%r15
mov    (%rsi),%rdi
mov    %edx,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
mov    (%r12),%rdi
call   1030 <strlen@plt>
lea    -0x1(%r14),%ecx
cmp    %ecx,%eax
jge    11c6 <zgetline+0x46>
mov    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    (%r14,%r14,1),%ebp
mov    %r14d,%ebx
jmp    1225 <zgetline+0xa5>
nop
mov    %ebp,%edi
call   1090 <our_malloc@plt>
mov    %rax,(%r12)
lea    0xe1e(%rip),%rdi
mov    $0x3d,%esi
call   10a0 <setup_error@plt>
xor    %edi,%edi
cmpq   $0x0,(%r12)
setne  %dil
xor    %esi,%esi
lea    0xe91(%rip),%rdx
call   1060 <int_cond_fatal@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
mov    (%r12),%rdi
call   1030 <strlen@plt>
lea    -0x1(%rbx),%ecx
add    %r14d,%ebp
cmp    %ecx,%eax
jl     11b5 <zgetline+0x35>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0xffffffff,%esi
call   1070 <fseek@plt>
mov    %r15,%rdi
call   1040 <fgetc@plt>
cmp    $0xa,%al
je     11b5 <zgetline+0x35>
lea    -0x1(%rbx),%eax
mov    (%r12),%rdi
movslq %eax,%r13
add    %rdi,%r13
add    %r14d,%ebx
test   %rdi,%rdi
je     11d0 <zgetline+0x50>
mov    %ebp,%esi
call   1080 <realloc@plt>
jmp    11d7 <zgetline+0x57>

LLVM IR (-O0):
@SEEK_CUR = global i32 0
@.str = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/tangentforks/zpl/refs/heads/master/comp/main/runpass.c\00"
@.str.1 = [29 x i8] c"Realloc failed in zgetline()\00"
define i32 @zgetline(i32* %0, i8** %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
store i32 0, i32* %10
%11 = load i8**, i8*** %5
%12 = load i8*, i8** %11
store i8* %12, i8** %7
%13 = load i32, i32* %6
store i32 %13, i32* %9
br label %14
14: ; preds = %73, %3
%15 = load i32, i32* %10
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %74
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = load i32, i32* %9
%21 = load i32*, i32** %4
%22 = call i32 @fgets(i8* %19, i32 %20, i32* %21)
%23 = load i8**, i8*** %5
%24 = load i8*, i8** %23
%25 = call i32 @strlen(i8* %24)
%26 = load i32, i32* %9
%27 = sub nsw i32 %26, 1
%28 = icmp slt i32 %25, %27
br i1 %28, label %29, label %30
29: ; preds = %18
store i32 1, i32* %10
br label %73
30: ; preds = %18
%31 = load i32*, i32** %4
%32 = load i32, i32* @SEEK_CUR
%33 = call i32 @fseek(i32* %31, i32 -1, i32 %32)
%34 = load i32*, i32** %4
%35 = call signext i8 @fgetc(i32* %34)
store i8 %35, i8* %8
%36 = load i8, i8* %8
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 10
br i1 %38, label %39, label %40
39: ; preds = %30
store i32 1, i32* %10
br label %72
40: ; preds = %30
%41 = load i8**, i8*** %5
%42 = load i8*, i8** %41
%43 = load i32, i32* %9
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8* %46, i8** %7
%47 = load i32, i32* %6
%48 = load i32, i32* %9
%49 = add nsw i32 %48, %47
store i32 %49, i32* %9
%50 = load i8**, i8*** %5
%51 = load i8*, i8** %50
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %60
53: ; preds = %40
%54 = load i8**, i8*** %5
%55 = load i8*, i8** %54
%56 = load i32, i32* %9
%57 = call i64 @realloc(i8* %55, i32 %56)
%58 = inttoptr i64 %57 to i8*
%59 = load i8**, i8*** %5
store i8* %58, i8** %59
br label %65
60: ; preds = %40
%61 = load i32, i32* %9
%62 = call i64 @our_malloc(i32 %61)
%63 = inttoptr i64 %62 to i8*
%64 = load i8**, i8*** %5
store i8* %63, i8** %64
br label %65
65: ; preds = %60, %53
%66 = call i32 @setup_error(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 61)
%67 = load i8**, i8*** %5
%68 = load i8*, i8** %67
%69 = icmp ne i8* %68, null
%70 = zext i1 %69 to i32
%71 = call i32 @int_cond_fatal(i32 %70, i32* null, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %72
72: ; preds = %65, %39
br label %73
73: ; preds = %72, %29
br label %14
74: ; preds = %14
%75 = load i32, i32* %9
ret i32 %75
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
@.str = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/tangentforks/zpl/refs/heads/master/comp/main/runpass.c\00"
@.str.1 = [29 x i8] c"Realloc failed in zgetline()\00"
define i32 @zgetline(i32* nocapture %0, i8** nocapture %1, i32 %2) {
%4 = load i8*, i8** %1
%5 = tail call i32 @fgets(i8* %4, i32 %2, i32* %0)
%6 = load i8*, i8** %1
%7 = tail call i32 @strlen(i8* %6)
%8 = add nsw i32 %2, -1
%9 = icmp slt i32 %7, %8
br i1 %9, label %40, label %10
10: ; preds = %3, %27
%11 = phi i32 [ %38, %27 ], [ %8, %3 ]
%12 = phi i32 [ %21, %27 ], [ %2, %3 ]
%13 = load i32, i32* @SEEK_CUR
%14 = tail call i32 @fseek(i32* %0, i32 -1, i32 %13)
%15 = tail call signext i8 @fgetc(i32* %0)
%16 = icmp eq i8 %15, 10
br i1 %16, label %40, label %17
17: ; preds = %10
%18 = load i8*, i8** %1
%19 = sext i32 %11 to i64
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = add nsw i32 %12, %2
%22 = icmp eq i8* %18, null
br i1 %22, label %25, label %23
23: ; preds = %17
%24 = tail call i64 @realloc(i8* %18, i32 %21)
br label %27
25: ; preds = %17
%26 = tail call i64 @our_malloc(i32 %21)
br label %27
27: ; preds = %23, %25
%28 = phi i64 [ %26, %25 ], [ %24, %23 ]
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %1
%30 = tail call i32 @setup_error(i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i32 61)
%31 = load i8*, i8** %1
%32 = icmp ne i8* %31, null
%33 = zext i1 %32 to i32
%34 = tail call i32 @int_cond_fatal(i32 %33, i32* null, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%35 = tail call i32 @fgets(i8* %20, i32 %21, i32* %0)
%36 = load i8*, i8** %1
%37 = tail call i32 @strlen(i8* %36)
%38 = add nsw i32 %21, -1
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %10
40: ; preds = %10, %27, %3
%41 = phi i32 [ %2, %3 ], [ %12, %10 ], [ %21, %27 ]
ret i32 %41
}