#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 EOF;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ gt_abort(char *);
scalar_t__ realloc(char *, size_t);
char *showg_getline(FILE *f) {
  static char *s;
  static size_t s_sz = 0;
  int c;
  long i;
  if ((size_t)(500) > s_sz) {
    if (s_sz)
      free(s);
    s_sz = (500);
    if ((s = (char *)calloc(500, sizeof(char))) == NULL)
      gt_abort("showg_getline");
  };
  i = 0;
  while ((c = getc(f)) != EOF && c != '\n') {
    if (i == s_sz - 2) {
      if ((size_t)(s_sz + 1000) > s_sz) {
        if ((s = (char *)realloc(s, (s_sz + 1000) * sizeof(char))) == NULL)
          gt_abort("showg_getline");
        else
          s_sz = (s_sz + 1000);
      }
    };
    s[i++] = c;
  }
  if (i == 0 && c == EOF)
    return NULL;
  if (c == '\n')
    s[i++] = '\n';
  s[i] = '\0';
  return s;
}


x86 assembly (clang, -O0):
<showg_getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x1f4,%eax
cmp    0x2ef0(%rip),%rax
jbe    11c4 <showg_getline+0x74>
cmpq   $0x0,0x2ee2(%rip)
je     1188 <showg_getline+0x38>
mov    0x2ecd(%rip),%rdi
call   1030 <free@plt>
movq   $0x1f4,0x2ec5(%rip)
mov    $0x1f4,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,0x2ea7(%rip)
cmp    $0x0,%rax
jne    11bf <showg_getline+0x6f>
lea    0xe46(%rip),%rdi
call   1040 <gt_abort@plt>
jmp    11c4 <showg_getline+0x74>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
mov    0x2e05(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x21(%rbp)
je     11f8 <showg_getline+0xa8>
cmpl   $0xa,-0x14(%rbp)
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1208 <showg_getline+0xb8>
jmp    12bb <showg_getline+0x16b>
mov    -0x20(%rbp),%rax
mov    0x2e45(%rip),%rcx
sub    $0x2,%rcx
cmp    %rcx,%rax
jne    1298 <showg_getline+0x148>
mov    0x2e31(%rip),%rax
add    $0x3e8,%rax
cmp    0x2e24(%rip),%rax
jbe    1293 <showg_getline+0x143>
mov    0x2e0f(%rip),%rdi
mov    0x2e10(%rip),%rsi
add    $0x3e8,%rsi
shl    $0x0,%rsi
call   1060 <realloc@plt>
mov    %rax,0x2df1(%rip)
cmp    $0x0,%rax
jne    127a <showg_getline+0x12a>
lea    0xd90(%rip),%rdi
call   1040 <gt_abort@plt>
jmp    128e <showg_getline+0x13e>
mov    0x2dd7(%rip),%rax
add    $0x3e8,%rax
mov    %rax,0x2dca(%rip)
jmp    1293 <showg_getline+0x143>
jmp    1298 <showg_getline+0x148>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    0x2dac(%rip),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    11cc <showg_getline+0x7c>
cmpq   $0x0,-0x20(%rbp)
jne    12e5 <showg_getline+0x195>
mov    -0x14(%rbp),%eax
mov    0x2d18(%rip),%rcx
cmp    (%rcx),%eax
jne    12e5 <showg_getline+0x195>
movq   $0x0,-0x8(%rbp)
jmp    1323 <showg_getline+0x1d3>
cmpl   $0xa,-0x14(%rbp)
jne    1309 <showg_getline+0x1b9>
mov    0x2d5a(%rip),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
movb   $0xa,(%rax,%rcx,1)
mov    0x2d40(%rip),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2d31(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showg_getline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    0x2ef6(%rip),%rax
cmp    $0x1f3,%rax
ja     11ad <showg_getline+0x5d>
test   %rax,%rax
je     117b <showg_getline+0x2b>
mov    0x2eda(%rip),%rdi
call   1030 <free@plt>
movq   $0x1f4,0x2ed2(%rip)
mov    $0x1f4,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,0x2eb4(%rip)
test   %rax,%rax
jne    11ad <showg_getline+0x5d>
lea    0xe58(%rip),%rdi
call   1040 <gt_abort@plt>
mov    %r15,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
mov    0x2e2a(%rip),%r12
mov    (%r12),%ecx
cmp    $0xa,%eax
je     1256 <showg_getline+0x106>
cmp    %ecx,%ebp
je     1256 <showg_getline+0x106>
xor    %ebx,%ebx
lea    0xe24(%rip),%r14
nopl   0x0(%rax)
mov    0x2e71(%rip),%rsi
cmp    $0xfffffffffffffc17,%rsi
ja     1230 <showg_getline+0xe0>
lea    -0x2(%rsi),%rax
cmp    %rax,%rbx
jne    1230 <showg_getline+0xe0>
add    $0x3e8,%rsi
mov    0x2e49(%rip),%rdi
call   1060 <realloc@plt>
mov    %rax,0x2e3d(%rip)
test   %rax,%rax
je     1225 <showg_getline+0xd5>
addq   $0x3e8,0x2e35(%rip)
jmp    1230 <showg_getline+0xe0>
mov    %r14,%rdi
call   1040 <gt_abort@plt>
nopl   (%rax)
mov    0x2e19(%rip),%rax
mov    %bpl,(%rax,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
cmp    $0xa,%eax
je     1261 <showg_getline+0x111>
cmp    (%r12),%ebp
jne    11e0 <showg_getline+0x90>
jmp    1261 <showg_getline+0x111>
xor    %ebx,%ebx
mov    $0x0,%eax
cmp    %ecx,%ebp
je     1279 <showg_getline+0x129>
mov    0x2de8(%rip),%rax
cmp    $0xa,%ebp
jne    1275 <showg_getline+0x125>
movb   $0xa,(%rax,%rbx,1)
add    $0x1,%rbx
movb   $0x0,(%rax,%rbx,1)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@showg_getline.s = internal global i8* null
@showg_getline.s_sz = internal global i64 0
@.str = [14 x i8] c"showg_getline\00"
@EOF = global i32 0
define i8* @showg_getline(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i64
store i32* %0, i32** %3
%6 = load i64, i64* @showg_getline.s_sz
%7 = icmp ugt i64 500, %6
br i1 %7, label %8, label %21
8: ; preds = %1
%9 = load i64, i64* @showg_getline.s_sz
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i8*, i8** @showg_getline.s
%13 = call i32 @free(i8* %12)
br label %14
14: ; preds = %11, %8
store i64 500, i64* @showg_getline.s_sz
%15 = call i64 @calloc(i32 500, i32 1)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** @showg_getline.s
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @gt_abort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
br label %21
21: ; preds = %20, %1
store i64 0, i64* %5
br label %22
22: ; preds = %57, %21
%23 = load i32*, i32** %3
%24 = call i32 @getc(i32* %23)
store i32 %24, i32* %4
%25 = load i32, i32* @EOF
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 10
br label %30
30: ; preds = %27, %22
%31 = phi i1 [ false, %22 ], [ %29, %27 ]
br i1 %31, label %32, label %64
32: ; preds = %30
%33 = load i64, i64* %5
%34 = load i64, i64* @showg_getline.s_sz
%35 = sub i64 %34, 2
%36 = icmp eq i64 %33, %35
br i1 %36, label %37, label %57
37: ; preds = %32
%38 = load i64, i64* @showg_getline.s_sz
%39 = add i64 %38, 1000
%40 = load i64, i64* @showg_getline.s_sz
%41 = icmp ugt i64 %39, %40
br i1 %41, label %42, label %56
42: ; preds = %37
%43 = load i8*, i8** @showg_getline.s
%44 = load i64, i64* @showg_getline.s_sz
%45 = add i64 %44, 1000
%46 = mul i64 %45, 1
%47 = call i64 @realloc(i8* %43, i64 %46)
%48 = inttoptr i64 %47 to i8*
store i8* %48, i8** @showg_getline.s
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %42
%51 = call i32 @gt_abort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %55
52: ; preds = %42
%53 = load i64, i64* @showg_getline.s_sz
%54 = add i64 %53, 1000
store i64 %54, i64* @showg_getline.s_sz
br label %55
55: ; preds = %52, %50
br label %56
56: ; preds = %55, %37
br label %57
57: ; preds = %56, %32
%58 = load i32, i32* %4
%59 = trunc i32 %58 to i8
%60 = load i8*, i8** @showg_getline.s
%61 = load i64, i64* %5
%62 = add nsw i64 %61, 1
store i64 %62, i64* %5
%63 = getelementptr inbounds i8, i8* %60, i64 %61
store i8 %59, i8* %63
br label %22
64: ; preds = %30
%65 = load i64, i64* %5
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load i32, i32* %4
%69 = load i32, i32* @EOF
%70 = icmp eq i32 %68, %69
br i1 %70, label %71, label %72
71: ; preds = %67
store i8* null, i8** %2
br label %85
72: ; preds = %67, %64
%73 = load i32, i32* %4
%74 = icmp eq i32 %73, 10
br i1 %74, label %75, label %80
75: ; preds = %72
%76 = load i8*, i8** @showg_getline.s
%77 = load i64, i64* %5
%78 = add nsw i64 %77, 1
store i64 %78, i64* %5
%79 = getelementptr inbounds i8, i8* %76, i64 %77
store i8 10, i8* %79
br label %80
80: ; preds = %75, %72
%81 = load i8*, i8** @showg_getline.s
%82 = load i64, i64* %5
%83 = getelementptr inbounds i8, i8* %81, i64 %82
store i8 0, i8* %83
%84 = load i8*, i8** @showg_getline.s
store i8* %84, i8** %2
br label %85
85: ; preds = %80, %71
%86 = load i8*, i8** %2
ret i8* %86
}

LLVM IR (-O2):
@showg_getline.s = internal unnamed_addr global i8* null
@showg_getline.s_sz = internal unnamed_addr global i64 0
@.str = [14 x i8] c"showg_getline\00"
@EOF = global i32 0
define i8* @showg_getline(i32* nocapture %0) {
%2 = load i64, i64* @showg_getline.s_sz
%3 = icmp ult i64 %2, 500
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = icmp eq i64 %2, 0
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = load i8*, i8** @showg_getline.s
%8 = tail call i32 @free(i8* %7)
br label %9
9: ; preds = %6, %4
store i64 500, i64* @showg_getline.s_sz
%10 = tail call i64 @calloc(i32 500, i32 1)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** @showg_getline.s
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i32 @gt_abort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %9, %13, %1
%16 = tail call i32 @getc(i32* %0)
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
%19 = icmp ne i32 %16, 10
%20 = and i1 %19, %18
br i1 %20, label %21, label %50
21: ; preds = %15, %40
%22 = phi i32 [ %45, %40 ], [ %16, %15 ]
%23 = phi i64 [ %43, %40 ], [ 0, %15 ]
%24 = load i64, i64* @showg_getline.s_sz
%25 = add i64 %24, -2
%26 = icmp eq i64 %23, %25
%27 = icmp ult i64 %24, -1000
%28 = and i1 %27, %26
br i1 %28, label %29, label %40
29: ; preds = %21
%30 = add nuw i64 %24, 1000
%31 = load i8*, i8** @showg_getline.s
%32 = tail call i64 @realloc(i8* %31, i64 %30)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** @showg_getline.s
%34 = icmp eq i64 %32, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = tail call i32 @gt_abort(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %40
37: ; preds = %29
%38 = load i64, i64* @showg_getline.s_sz
%39 = add i64 %38, 1000
store i64 %39, i64* @showg_getline.s_sz
br label %40
40: ; preds = %37, %35, %21
%41 = trunc i32 %22 to i8
%42 = load i8*, i8** @showg_getline.s
%43 = add nuw nsw i64 %23, 1
%44 = getelementptr inbounds i8, i8* %42, i64 %23
store i8 %41, i8* %44
%45 = tail call i32 @getc(i32* %0)
%46 = load i32, i32* @EOF
%47 = icmp ne i32 %45, %46
%48 = icmp ne i32 %45, 10
%49 = and i1 %48, %47
br i1 %49, label %21, label %52
50: ; preds = %15
%51 = icmp eq i32 %16, %17
br i1 %51, label %63, label %52
52: ; preds = %40, %50
%53 = phi i32 [ %16, %50 ], [ %45, %40 ]
%54 = phi i64 [ 0, %50 ], [ %43, %40 ]
%55 = icmp eq i32 %53, 10
%56 = load i8*, i8** @showg_getline.s
br i1 %55, label %57, label %60
57: ; preds = %52
%58 = add nuw nsw i64 %54, 1
%59 = getelementptr inbounds i8, i8* %56, i64 %54
store i8 10, i8* %59
br label %60
60: ; preds = %52, %57
%61 = phi i64 [ %58, %57 ], [ %54, %52 ]
%62 = getelementptr inbounds i8, i8* %56, i64 %61
store i8 0, i8* %62
br label %63
63: ; preds = %50, %60
%64 = phi i8* [ %56, %60 ], [ null, %50 ]
ret i8* %64
}