#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*/ assert(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ test_line_length(char *);
int load_lines(int count, FILE *fd, char **buffer) {
  assert(fd != NULL && buffer != NULL);
  int pos = 0;
  while (fgets(buffer[pos], 1024, fd) != NULL) {
    if (test_line_length(buffer[pos]))
      return -1;
    pos++;
    if (pos == count)
      pos = 0;
  }
  return pos;
}


x86 assembly (clang, -O0):
<load_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x1d(%rbp)
je     115e <load_lines+0x2e>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11de <load_lines+0xae>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <test_line_length@plt>
cmp    $0x0,%rax
je     11bd <load_lines+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <load_lines+0xb4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11d9 <load_lines+0xa9>
movl   $0x0,-0x1c(%rbp)
jmp    1172 <load_lines+0x42>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r14
mov    %edi,%r15d
test   %rsi,%rsi
setne  %al
test   %rdx,%rdx
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    0x0(%r13),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11be <load_lines+0x8e>
xor    %r12d,%r12d
mov    %r13,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
call   1050 <test_line_length@plt>
test   %rax,%rax
jne    11c2 <load_lines+0x92>
add    $0x1,%ebp
cmp    %r15d,%ebp
cmove  %r12d,%ebp
movslq %ebp,%rax
lea    0x0(,%rax,8),%rbx
add    %r13,%rbx
mov    0x0(%r13,%rax,8),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
jne    1180 <load_lines+0x50>
jmp    11c7 <load_lines+0x97>
xor    %ebp,%ebp
jmp    11c7 <load_lines+0x97>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @load_lines(i32 %0, i32* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i8** %2, i8*** %7
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8**, i8*** %7
%13 = icmp ne i8** %12, null
br label %14
14: ; preds = %11, %3
%15 = phi i1 [ false, %3 ], [ %13, %11 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
store i32 0, i32* %8
br label %18
18: ; preds = %43, %14
%19 = load i8**, i8*** %7
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = load i32*, i32** %6
%25 = call i32* @fgets(i8* %23, i32 1024, i32* %24)
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %44
27: ; preds = %18
%28 = load i8**, i8*** %7
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i64 @test_line_length(i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %27
store i32 -1, i32* %4
br label %46
36: ; preds = %27
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = load i32, i32* %5
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %43
42: ; preds = %36
store i32 0, i32* %8
br label %43
43: ; preds = %42, %36
br label %18
44: ; preds = %18
%45 = load i32, i32* %8
store i32 %45, i32* %4
br label %46
46: ; preds = %44, %35
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
define i32 @load_lines(i32 %0, i32* %1, i8** %2) {
%4 = icmp ne i32* %1, null
%5 = icmp ne i8** %2, null
%6 = and i1 %4, %5
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = load i8*, i8** %2
%10 = tail call i32* @fgets(i8* %9, i32 1024, i32* %1)
%11 = icmp eq i32* %10, null
br i1 %11, label %27, label %12
12: ; preds = %3, %18
%13 = phi i8** [ %23, %18 ], [ %2, %3 ]
%14 = phi i32 [ %21, %18 ], [ 0, %3 ]
%15 = load i8*, i8** %13
%16 = tail call i64 @test_line_length(i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %12
%19 = add nsw i32 %14, 1
%20 = icmp eq i32 %19, %0
%21 = select i1 %20, i32 0, i32 %19
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %2, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i32* @fgets(i8* %24, i32 1024, i32* %1)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %12
27: ; preds = %12, %18, %3
%28 = phi i32 [ 0, %3 ], [ %21, %18 ], [ -1, %12 ]
ret i32 %28
}