#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 */
scalar_t__ calloc(size_t, size_t);
int /*<<< orphan*/ check_alloc(char *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *realloc(char *, size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *myfgets(char *str, int *size, FILE *fin, unsigned int verbosity) {
  char *ret;
  char *hstr = NULL;
  char last;
  ret = fgets(str, *size, fin);
  if (ret == NULL)
    return NULL;
  last = str[strlen(str) - 1];
  while (last != '\n') {
    *size += 1024;
    check_alloc(hstr = (char *)calloc((size_t)1024, (size_t)1));
    check_alloc(str = realloc(str, (size_t)*size));
    ret = fgets(hstr, 1024, fin);
    strcat(str, hstr);
    if (verbosity & 0x1)
      fprintf(stderr, "Line in file too long. Increasing input size\n");
    last = str[strlen(str) - 1];
    free(hstr);
  }
  if (ret == NULL)
    return NULL;
  else
    return str;
}


x86 assembly (clang, -O0):
<myfgets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ce <myfgets+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    12db <myfgets+0x15b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x39(%rbp)
movsbl -0x39(%rbp),%eax
cmp    $0xa,%eax
je     12bb <myfgets+0x13b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x400,%ecx
mov    %ecx,(%rax)
mov    $0x400,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rdi
mov    %rdi,-0x38(%rbp)
call   10a0 <check_alloc@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rsi
call   1080 <realloc@plt>
mov    %rax,%rdi
mov    %rdi,-0x10(%rbp)
call   10a0 <check_alloc@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x24(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     128a <myfgets+0x10a>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
lea    0xd7b(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x39(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    11f1 <myfgets+0x71>
cmpq   $0x0,-0x30(%rbp)
jne    12d3 <myfgets+0x153>
movq   $0x0,-0x8(%rbp)
jmp    12db <myfgets+0x15b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myfgets>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,0x4(%rsp)
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    (%rsi),%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1265 <myfgets+0xe5>
mov    %rax,%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11ee <myfgets+0x6e>
test   %r13,%r13
cmove  %r13,%rbx
jmp    1267 <myfgets+0xe7>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movzbl -0x1(%rax,%rbx,1),%r14d
mov    %r12,%rdi
call   1030 <free@plt>
cmp    $0xa,%r14b
je     11bc <myfgets+0x3c>
addl   $0x400,0x0(%rbp)
mov    $0x400,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   10a0 <check_alloc@plt>
movslq 0x0(%rbp),%rsi
mov    %rbx,%rdi
call   1080 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <check_alloc@plt>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
testb  $0x1,0x4(%rsp)
je     11d0 <myfgets+0x50>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11d0 <myfgets+0x50>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"Line in file too long. Increasing input size\0A\00"
define i8* @myfgets(i8* %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i8* null, i8** %11
%13 = load i8*, i8** %6
%14 = load i32*, i32** %7
%15 = load i32, i32* %14
%16 = load i32*, i32** %8
%17 = call i8* @fgets(i8* %13, i32 %15, i32* %16)
store i8* %17, i8** %10
%18 = load i8*, i8** %10
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %4
store i8* null, i8** %5
br label %74
21: ; preds = %4
%22 = load i8*, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = load i8, i8* %27
store i8 %28, i8* %12
br label %29
29: ; preds = %58, %21
%30 = load i8, i8* %12
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %68
33: ; preds = %29
%34 = load i32*, i32** %7
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1024
store i32 %36, i32* %34
%37 = call i64 @calloc(i64 1024, i64 1)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %11
%39 = call i32 @check_alloc(i8* %38)
%40 = load i8*, i8** %6
%41 = load i32*, i32** %7
%42 = load i32, i32* %41
%43 = sext i32 %42 to i64
%44 = call i8* @realloc(i8* %40, i64 %43)
store i8* %44, i8** %6
%45 = call i32 @check_alloc(i8* %44)
%46 = load i8*, i8** %11
%47 = load i32*, i32** %8
%48 = call i8* @fgets(i8* %46, i32 1024, i32* %47)
store i8* %48, i8** %10
%49 = load i8*, i8** %6
%50 = load i8*, i8** %11
%51 = call i32 @strcat(i8* %49, i8* %50)
%52 = load i32, i32* %9
%53 = and i32 %52, 1
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %33
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %58
58: ; preds = %55, %33
%59 = load i8*, i8** %6
%60 = load i8*, i8** %6
%61 = call i32 @strlen(i8* %60)
%62 = sub nsw i32 %61, 1
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %59, i64 %63
%65 = load i8, i8* %64
store i8 %65, i8* %12
%66 = load i8*, i8** %11
%67 = call i32 @free(i8* %66)
br label %29
68: ; preds = %29
%69 = load i8*, i8** %10
%70 = icmp eq i8* %69, null
br i1 %70, label %71, label %72
71: ; preds = %68
store i8* null, i8** %5
br label %74
72: ; preds = %68
%73 = load i8*, i8** %6
store i8* %73, i8** %5
br label %74
74: ; preds = %72, %71, %20
%75 = load i8*, i8** %5
ret i8* %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"Line in file too long. Increasing input size\0A\00"
define i8* @myfgets(i8* %0, i32* nocapture %1, i32* nocapture %2, i32 %3) {
%5 = load i32, i32* %1
%6 = tail call i8* @fgets(i8* %0, i32 %5, i32* %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %47, label %8
8: ; preds = %4
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %42, label %15
15: ; preds = %8
%16 = and i32 %3, 1
%17 = icmp eq i32 %16, 0
br label %18
18: ; preds = %15, %34
%19 = phi i8* [ %0, %15 ], [ %27, %34 ]
%20 = load i32, i32* %1
%21 = add nsw i32 %20, 1024
store i32 %21, i32* %1
%22 = tail call i64 @calloc(i64 1024, i64 1)
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @check_alloc(i8* %23)
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = tail call i8* @realloc(i8* %19, i64 %26)
%28 = tail call i32 @check_alloc(i8* %27)
%29 = tail call i8* @fgets(i8* %23, i32 1024, i32* %2)
%30 = tail call i32 @strcat(i8* %27, i8* %23)
br i1 %17, label %34, label %31
31: ; preds = %18
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %31, %18
%35 = tail call i32 @strlen(i8* %27)
%36 = add nsw i32 %35, -1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %27, i64 %37
%39 = load i8, i8* %38
%40 = tail call i32 @free(i8* %23)
%41 = icmp eq i8 %39, 10
br i1 %41, label %42, label %18
42: ; preds = %34, %8
%43 = phi i8* [ %0, %8 ], [ %27, %34 ]
%44 = phi i8* [ %6, %8 ], [ %29, %34 ]
%45 = icmp eq i8* %44, null
%46 = select i1 %45, i8* null, i8* %43
br label %47
47: ; preds = %42, %4
%48 = phi i8* [ null, %4 ], [ %46, %42 ]
ret i8* %48
}