#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 */
char **alloc_buffer(int);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ free_buffer(char **, int);
int load_lines(int, int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ print_lines(int, char **, int);
int /*<<< orphan*/ *stdin;
void print_end(FILE *fd, int line_count) {
  assert(fd != NULL);
  int zero_count = (line_count == 0) ? 1 : 0;
  if (zero_count)
    line_count = 1;
  char **buffer = alloc_buffer(line_count);
  if (buffer == NULL) {
    if (fd == stdin)
      fclose(fd);
    error("Not enough memory!\n");
  }
  int pos = load_lines(line_count, fd, buffer);
  if (pos < 0) {
    if (fd == stdin)
      fclose(fd);
    free_buffer(buffer, line_count);
    error("Input line too long!\n");
  }
  if (!zero_count)
    print_lines(pos, buffer, line_count);
  free_buffer(buffer, line_count);
}


x86 assembly (clang, -O0):
<print_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0xc(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11b5 <print_end+0x45>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1090 <alloc_buffer@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f5 <print_end+0x85>
mov    -0x8(%rbp),%rax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
jne    11e9 <print_end+0x79>
mov    -0x8(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xe10(%rip),%rdi
call   1080 <error@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <load_lines@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1247 <print_end+0xd7>
mov    -0x8(%rbp),%rax
mov    0x2dcb(%rip),%rcx
cmp    (%rcx),%rax
jne    122f <print_end+0xbf>
mov    -0x8(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <free_buffer@plt>
lea    0xdd2(%rip),%rdi
call   1080 <error@plt>
cmpl   $0x0,-0x10(%rbp)
jne    1260 <print_end+0xf0>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <print_lines@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <free_buffer@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_end>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1070 <assert@plt>
test   %r14d,%r14d
mov    $0x1,%ebx
cmovne %r14d,%ebx
mov    %ebx,%edi
call   1090 <alloc_buffer@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11c7 <print_end+0x57>
mov    0x2e3a(%rip),%rax
cmp    %r15,(%rax)
jne    11bb <print_end+0x4b>
mov    %r15,%rdi
call   1060 <fclose@plt>
lea    0xe3e(%rip),%rdi
call   1080 <error@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1050 <load_lines@plt>
mov    %eax,%r12d
test   %eax,%eax
jns    1205 <print_end+0x95>
mov    0x2e06(%rip),%rax
cmp    %r15,(%rax)
jne    11ef <print_end+0x7f>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1030 <free_buffer@plt>
lea    0xe14(%rip),%rdi
call   1080 <error@plt>
test   %r14d,%r14d
je     1217 <print_end+0xa7>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1040 <print_lines@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free_buffer@plt>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [20 x i8] c"Not enough memory!\0A\00"
@.str.1 = [22 x i8] c"Input line too long!\0A\00"
define void @print_end(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 1, i32 0
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 1, i32* %4
br label %19
19: ; preds = %18, %2
%20 = load i32, i32* %4
%21 = call i8** @alloc_buffer(i32 %20)
store i8** %21, i8*** %6
%22 = load i8**, i8*** %6
%23 = icmp eq i8** %22, null
br i1 %23, label %24, label %33
24: ; preds = %19
%25 = load i32*, i32** %3
%26 = load i32*, i32** @stdin
%27 = icmp eq i32* %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32*, i32** %3
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %28, %24
%32 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %19
%34 = load i32, i32* %4
%35 = load i32*, i32** %3
%36 = load i8**, i8*** %6
%37 = call i32 @load_lines(i32 %34, i32* %35, i8** %36)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %33
%41 = load i32*, i32** %3
%42 = load i32*, i32** @stdin
%43 = icmp eq i32* %41, %42
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i32*, i32** %3
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %44, %40
%48 = load i8**, i8*** %6
%49 = load i32, i32* %4
%50 = call i32 @free_buffer(i8** %48, i32 %49)
%51 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %52
52: ; preds = %47, %33
%53 = load i32, i32* %5
%54 = icmp ne i32 %53, 0
br i1 %54, label %60, label %55
55: ; preds = %52
%56 = load i32, i32* %7
%57 = load i8**, i8*** %6
%58 = load i32, i32* %4
%59 = call i32 @print_lines(i32 %56, i8** %57, i32 %58)
br label %60
60: ; preds = %55, %52
%61 = load i8**, i8*** %6
%62 = load i32, i32* %4
%63 = call i32 @free_buffer(i8** %61, i32 %62)
ret void
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [20 x i8] c"Not enough memory!\0A\00"
@.str.1 = [22 x i8] c"Input line too long!\0A\00"
define void @print_end(i32* %0, i32 %1) {
%3 = icmp ne i32* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp eq i32 %1, 0
%7 = select i1 %6, i32 1, i32 %1
%8 = tail call i8** @alloc_buffer(i32 %7)
%9 = icmp eq i8** %8, null
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32*, i32** @stdin
%12 = icmp eq i32* %11, %0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = tail call i32 @fclose(i32* %0)
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = tail call i32 @load_lines(i32 %7, i32* %0, i8** %8)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i32*, i32** @stdin
%22 = icmp eq i32* %21, %0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @fclose(i32* %0)
br label %25
25: ; preds = %23, %20
%26 = tail call i32 @free_buffer(i8** %8, i32 %7)
%27 = tail call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %17
br i1 %6, label %31, label %29
29: ; preds = %28
%30 = tail call i32 @print_lines(i32 %18, i8** %8, i32 %7)
br label %31
31: ; preds = %29, %28
%32 = tail call i32 @free_buffer(i8** %8, i32 %7)
ret void
}