#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 */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
int getline(int, char **, size_t *);
int open(char *, int /*<<< orphan*/);
int main(void) {
  char *input = NULL;
  size_t size;
  int fd, ret;
  input = NULL;
  size = 0;
  ret = getline(-1, &input, &size);
  assert(ret != 0);
  assert(input == NULL);
  assert(size == 0);
  ret = getline(0, NULL, &size);
  assert(ret != 0);
  assert(input == NULL);
  assert(size == 0);
  ret = getline(0, &input, NULL);
  assert(ret != 0);
  assert(input == NULL);
  assert(size == 0);
  fd = open("getline.c", O_RDONLY);
  assert(fd >= 0);
  input = NULL;
  size = 0;
  ret = getline(fd, &input, &size);
  assert(ret == 0);
  assert(input != NULL);
  assert(size != 0);
  assert(size == 64 + 1);
  if (input != NULL) {
    free(input);
    input = NULL;
  }
  close(fd);
  fd = -1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0xffffffff,%edi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <getline@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
call   1070 <getline@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <getline@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
lea    0xda1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <getline@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x41,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
je     12fe <main+0x1ae>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x1c(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rbx
lea    0x8(%rsp),%r14
mov    $0xffffffff,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getline@plt>
xor    %edi,%edi
test   %eax,%eax
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,0x8(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1070 <getline@plt>
xor    %edi,%edi
test   %eax,%eax
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,0x8(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1070 <getline@plt>
xor    %edi,%edi
test   %eax,%eax
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%rsp)
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,0x8(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
lea    0xdcd(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1070 <getline@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%rsp)
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,0x8(%rsp)
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpq   $0x41,0x8(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     12b9 <main+0x169>
call   1030 <free@plt>
movq   $0x0,(%rsp)
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"getline.c\00"
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i8* null, i8** %2
store i8* null, i8** %2
store i64 0, i64* %3
%6 = call i32 @getline(i32 -1, i8** %2, i64* %3)
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %2
%12 = icmp eq i8* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i64, i64* %3
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32 @getline(i32 0, i8** null, i64* %3)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i8*, i8** %2
%25 = icmp eq i8* %24, null
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i64, i64* %3
%29 = icmp eq i64 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 @getline(i32 0, i8** %2, i64* null)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i8*, i8** %2
%38 = icmp eq i8* %37, null
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i64, i64* %3
%42 = icmp eq i64 %41, 0
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
%45 = load i32, i32* @O_RDONLY
%46 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %45)
store i32 %46, i32* %4
%47 = load i32, i32* %4
%48 = icmp sge i32 %47, 0
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
store i8* null, i8** %2
store i64 0, i64* %3
%51 = load i32, i32* %4
%52 = call i32 @getline(i32 %51, i8** %2, i64* %3)
store i32 %52, i32* %5
%53 = load i32, i32* %5
%54 = icmp eq i32 %53, 0
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = load i8*, i8** %2
%58 = icmp ne i8* %57, null
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load i64, i64* %3
%62 = icmp ne i64 %61, 0
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = load i64, i64* %3
%66 = icmp eq i64 %65, 65
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i8*, i8** %2
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %0
%72 = load i8*, i8** %2
%73 = call i32 @free(i8* %72)
store i8* null, i8** %2
br label %74
74: ; preds = %71, %0
%75 = load i32, i32* %4
%76 = call i32 @close(i32 %75)
store i32 -1, i32* %4
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"getline.c\00"
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = bitcast i8** %1 to i8*
%4 = bitcast i64* %2 to i8*
store i8* null, i8** %1
store i64 0, i64* %2
%5 = call i32 @getline(i32 -1, i8** %1, i64* %2)
%6 = icmp ne i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i8*, i8** %1
%10 = icmp eq i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i64, i64* %2
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @getline(i32 0, i8** null, i64* %2)
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i8*, i8** %1
%22 = icmp eq i8* %21, null
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i64, i64* %2
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @getline(i32 0, i8** %1, i64* null)
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i8*, i8** %1
%34 = icmp eq i8* %33, null
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i64, i64* %2
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i32, i32* @O_RDONLY
%42 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = xor i32 %42, -1
%44 = lshr i32 %43, 31
%45 = call i32 @assert(i32 %44)
store i8* null, i8** %1
store i64 0, i64* %2
%46 = call i32 @getline(i32 %42, i8** %1, i64* %2)
%47 = icmp eq i32 %46, 0
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i8*, i8** %1
%51 = icmp ne i8* %50, null
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i64, i64* %2
%55 = icmp ne i64 %54, 0
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = load i64, i64* %2
%59 = icmp eq i64 %58, 65
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = load i8*, i8** %1
%63 = icmp eq i8* %62, null
br i1 %63, label %66, label %64
64: ; preds = %0
%65 = call i32 @free(i8* %62)
store i8* null, i8** %1
br label %66
66: ; preds = %64, %0
%67 = call i32 @close(i32 %42)
ret i32 0
}