#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__ EOF;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getline(char **, int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
size_t getLine(char **string, FILE *stream) {
  FILE *fd;
  char *str = NULL;
  int rd = 0;
  int ln = getline(&str, &rd, fd);
  if (ln == -1) {
    fprintf(stderr, "error in reading string\n");
    exit(-1);
  } else {
    while (fgetc(fd) != EOF) {
      ++rd;
    }
  }
  if (feof(fd) != 0) {
    printf("%x\n", rd);
    exit(EXIT_SUCCESS);
  }
  return -1;
}


x86 assembly (clang, -O0):
<getLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    11bc <getLine+0x5c>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    11c1 <getLine+0x61>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%rax
je     11e8 <getLine+0x88>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c1 <getLine+0x61>
jmp    11ed <getLine+0x8d>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     121d <getLine+0xbd>
mov    -0x24(%rbp),%esi
lea    0xe0f(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0xffffffffffffffff,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLine>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     11c6 <getLine+0x66>
call   1040 <fgetc@plt>
mov    0x2e52(%rip),%rbx
cmp    (%rbx),%rax
je     11af <getLine+0x4f>
nopl   0x0(%rax,%rax,1)
addl   $0x1,0x4(%rsp)
call   1040 <fgetc@plt>
cmp    (%rbx),%rax
jne    11a0 <getLine+0x40>
call   1060 <feof@plt>
test   %rax,%rax
jne    11e5 <getLine+0x85>
mov    $0xffffffffffffffff,%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0x4(%rsp),%esi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"error in reading string\0A\00"
@EOF = global i64 0
@.str.1 = [4 x i8] c"%x\0A\00"
@EXIT_SUCCESS = global i32 0
define i64 @getLine(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %3
store i32* %1, i32** %4
store i8* null, i8** %6
store i32 0, i32* %7
%9 = load i32*, i32** %5
%10 = call i32 @getline(i8** %6, i32* %7, i32* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %23, %17
%19 = load i32*, i32** %5
%20 = call i64 @fgetc(i32* %19)
%21 = load i64, i64* @EOF
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %18
26: ; preds = %18
br label %27
27: ; preds = %26
%28 = load i32*, i32** %5
%29 = call i64 @feof(i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = load i32, i32* %7
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i32, i32* @EXIT_SUCCESS
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %27
ret i64 -1
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"error in reading string\0A\00"
@EOF = global i64 0
@.str.1 = [4 x i8] c"%x\0A\00"
@EXIT_SUCCESS = global i32 0
define i64 @getLine(i8** nocapture readnone %0, i32* nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = call i32 @getline(i8** %3, i32* %4, i32* undef)
%8 = icmp eq i32 %7, -1
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = call i64 @fgetc(i32* undef)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
br i1 %12, label %23, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %9, %17
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
%20 = call i64 @fgetc(i32* undef)
%21 = load i64, i64* @EOF
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %17
23: ; preds = %17, %9
%24 = call i64 @feof(i32* undef)
%25 = icmp eq i64 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @EXIT_SUCCESS
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %23
ret i64 -1
}