#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 scalar_t__ u_short;
typedef int u_long;
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int getline(char **, int *, int /*<<< orphan*/ *);
char *realloc(char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
u_long get_n_pass(FILE *fp, char **buf, u_short cnt) {
  char *line;
  ssize_t i, len = 0, count = 0;
  u_long length = 0;
  while (count++ < cnt) {
    line = NULL;
    i = getline(&line, &len, fp);
    if (i != -1) {
      *buf = realloc(*buf, length + i);
      *(line + i - 1) = '\xff';
      strncpy(*buf + length, line, i);
      length += i;
    }
    free(line);
  }
  return length;
}


x86 assembly (clang, -O0):
<get_n_pass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cltq
cmp    -0x18(%rbp),%rax
jge    1200 <get_n_pass+0xc0>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     11f2 <get_n_pass+0xb2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%esi
add    -0x24(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0xff,-0x1(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x24(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    1169 <get_n_pass+0x29>
mov    -0x30(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_n_pass>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x14(%rsp)
test   %rdx,%rdx
jle    11da <get_n_pass+0x9a>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebp,%ebp
jmp    1180 <get_n_pass+0x40>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0xffffffffffffffff,%rbx
je     11dc <get_n_pass+0x9c>
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x14(%rsp),%rsi
mov    %r15,%rdx
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     1170 <get_n_pass+0x30>
mov    %eax,%r12d
mov    (%r14),%rdi
lea    (%r12,%rbp,1),%r13d
mov    %r13d,%esi
call   1050 <realloc@plt>
mov    %rax,(%r14)
mov    0x8(%rsp),%rax
movslq %r12d,%rcx
movb   $0xff,-0x1(%rax,%rcx,1)
movslq %ebp,%rdi
add    (%r14),%rdi
mov    0x8(%rsp),%rsi
mov    %r12d,%edx
call   1040 <strncpy@plt>
mov    %r13d,%ebp
jmp    1170 <get_n_pass+0x30>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @get_n_pass(i32* %0, i8** nocapture %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = bitcast i8** %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%8 = icmp sgt i64 %2, 0
br i1 %8, label %9, label %33
9: ; preds = %3, %27
%10 = phi i64 [ %31, %27 ], [ 1, %3 ]
%11 = phi i32 [ %28, %27 ], [ 0, %3 ]
store i8* null, i8** %4
%12 = call i32 @getline(i8** %4, i32* %5, i32* %0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %27, label %14
14: ; preds = %9
%15 = load i8*, i8** %1
%16 = add nsw i32 %12, %11
%17 = call i8* @realloc(i8* %15, i32 %16)
store i8* %17, i8** %1
%18 = load i8*, i8** %4
%19 = sext i32 %12 to i64
%20 = getelementptr inbounds i8, i8* %18, i64 -1
%21 = getelementptr inbounds i8, i8* %20, i64 %19
store i8 -1, i8* %21
%22 = load i8*, i8** %1
%23 = sext i32 %11 to i64
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8*, i8** %4
%26 = call i32 @strncpy(i8* %24, i8* %25, i32 %12)
br label %27
27: ; preds = %14, %9
%28 = phi i32 [ %16, %14 ], [ %11, %9 ]
%29 = load i8*, i8** %4
%30 = call i32 @free(i8* %29)
%31 = add nuw i64 %10, 1
%32 = icmp eq i64 %10, %2
br i1 %32, label %33, label %9
33: ; preds = %27, %3
%34 = phi i32 [ 0, %3 ], [ %28, %27 ]
ret i32 %34
}