#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*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
char *readLine(FILE *fp) {
  char *buffer = (char *)malloc(sizeof(char) * 128);
  do {
    fgets(buffer, 128, fp);
    if (buffer == NULL) {
      fputs("Out of memory :(", stderr);
      exit(1);
    }
  } while (buffer[0] == '#');
  return buffer;
}


x86 assembly (clang, -O0):
<readLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x80,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x80,%esi
call   1040 <fgets@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1196 <readLine+0x56>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1030 <fputs@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    119b <readLine+0x5b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     115a <readLine+0x1a>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLine>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x80,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rbx,%rbx
je     1185 <readLine+0x45>
cmpb   $0x23,(%rbx)
je     1160 <readLine+0x20>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
call   1030 <fputs@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Out of memory :(\00"
@stderr = global i32 0
define i8* @readLine(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
store i32* %0, i32** %2
%4 = call i64 @malloc(i32 128)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
br label %6
6: ; preds = %17, %1
%7 = load i8*, i8** %3
%8 = load i32*, i32** %2
%9 = call i32 @fgets(i8* %7, i32 128, i32* %8)
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %6
br label %17
17: ; preds = %16
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 35
br i1 %22, label %6, label %23
23: ; preds = %17
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@.str = [17 x i8] c"Out of memory :(\00"
@stderr = global i32 0
define i8* @readLine(i32* nocapture %0) {
%2 = tail call i64 @malloc(i32 128)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br label %5
5: ; preds = %11, %1
%6 = tail call i32 @fgets(i8* %3, i32 128, i32* %0)
br i1 %4, label %7, label %11
7: ; preds = %5
%8 = load i32, i32* @stderr
%9 = tail call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5
%12 = load i8, i8* %3
%13 = icmp eq i8 %12, 35
br i1 %13, label %5, label %14
14: ; preds = %11
ret i8* %3
}