#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 */

/* Variables and functions */
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
char *pbc_strdup(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *pbc_getline(const char *prompt) {
  char s[1024];
  if (prompt)
    fputs(prompt, stdout);
  if (!fgets(s, 1024, stdin))
    return NULL;
  if (feof(stdin))
    return NULL;
  return pbc_strdup(s);
}


x86 assembly (clang, -O0):
<pbc_getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116c <pbc_getline+0x2c>
mov    -0x10(%rbp),%rdi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    119c <pbc_getline+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <pbc_getline+0x91>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11c1 <pbc_getline+0x81>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <pbc_getline+0x91>
lea    -0x410(%rbp),%rdi
call   1050 <pbc_strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pbc_getline>:
push   %rbx
sub    $0x400,%rsp
test   %rdi,%rdi
je     115b <pbc_getline+0x1b>
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    0x2e86(%rip),%rbx
mov    (%rbx),%edx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %eax,%eax
je     1181 <pbc_getline+0x41>
mov    (%rbx),%edi
call   1060 <feof@plt>
test   %rax,%rax
je     1185 <pbc_getline+0x45>
xor    %eax,%eax
jmp    118d <pbc_getline+0x4d>
mov    %rsp,%rdi
call   1050 <pbc_strdup@plt>
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@stdin = global i32 0
define i8* @pbc_getline(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [1024 x i8]
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i32, i32* @stdout
%10 = call i32 @fputs(i8* %8, i32 %9)
br label %11
11: ; preds = %7, %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 1024, i32 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %11
store i8* null, i8** %2
br label %25
17: ; preds = %11
%18 = load i32, i32* @stdin
%19 = call i64 @feof(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i8* null, i8** %2
br label %25
22: ; preds = %17
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = call i8* @pbc_strdup(i8* %23)
store i8* %24, i8** %2
br label %25
25: ; preds = %22, %21, %16
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
define i8* @pbc_getline(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = load i32, i32* @stdout
%7 = tail call i32 @fputs(i8* %0, i32 %6)
br label %8
8: ; preds = %5, %1
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %3, i32 1024, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = load i32, i32* @stdin
%14 = call i64 @feof(i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i8* @pbc_strdup(i8* %3)
br label %18
18: ; preds = %12, %8, %16
%19 = phi i8* [ %17, %16 ], [ null, %8 ], [ null, %12 ]
ret i8* %19
}