#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*/ chomp(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int get_pig(char *filename, char **pig[]) {
  FILE *f;
  char buffer[256];
  char *line;
  char **temp_pig;
  int i;
  f = fopen(filename, "r");
  if (f == NULL) {
    return -1;
  }
  temp_pig = (char **)malloc(sizeof(char *) * (100 + 1));
  if (temp_pig == NULL) {
    fprintf(stderr, "Error allocating memory in get_pig\n");
    exit(1);
  }
  for (i = 0; fgets(buffer, 256, f) && i < 100; i++) {
    line = (char *)malloc(sizeof(char) * (strlen(buffer) + 1));
    if (line == NULL) {
      fprintf(stderr, "Error allocating memory in get_pig\n");
      exit(1);
    }
    strncpy(line, buffer, strlen(buffer) + 1);
    chomp(line);
    temp_pig[i] = line;
  }
  temp_pig[i] = NULL;
  *pig = temp_pig;
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<get_pig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ce <get_pig+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1360 <get_pig+0x1d0>
mov    $0x328,%edi
call   1080 <malloc@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    120c <get_pig+0x7c>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movl   $0x0,-0x134(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x135(%rbp)
je     1250 <get_pig+0xc0>
cmpl   $0x64,-0x134(%rbp)
setl   %al
mov    %al,-0x135(%rbp)
mov    -0x135(%rbp),%al
test   $0x1,%al
jne    1263 <get_pig+0xd3>
jmp    132c <get_pig+0x19c>
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    12b3 <get_pig+0x123>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x128(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x128(%rbp),%rdi
call   1090 <chomp@plt>
mov    -0x128(%rbp),%rdx
mov    -0x130(%rbp),%rax
movslq -0x134(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1216 <get_pig+0x86>
mov    -0x130(%rbp),%rax
movslq -0x134(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x130(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pig>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1263 <get_pig+0xd3>
mov    %rax,%r15
mov    $0x328,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     129b <get_pig+0x10b>
mov    %rax,%r13
mov    %rbx,0x8(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     126b <get_pig+0xdb>
xor    %r14d,%r14d
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     129b <get_pig+0x10b>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1090 <chomp@plt>
mov    %rbp,0x0(%r13,%r14,8)
lea    0x1(%r14),%rbp
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     126d <get_pig+0xdd>
cmp    $0x63,%r14
mov    %rbp,%r14
jb     1200 <get_pig+0x70>
jmp    126d <get_pig+0xdd>
mov    $0xffffffff,%r12d
jmp    1286 <get_pig+0xf6>
xor    %ebp,%ebp
movq   $0x0,0x0(%r13,%rbp,8)
mov    0x8(%rsp),%rax
mov    %r13,(%rax)
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r12d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
lea    0xd57(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Error allocating memory in get_pig\0A\00"
define i32 @get_pig(i8* %0, i8*** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8***
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32
store i8* %0, i8** %4
store i8*** %1, i8**** %5
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 -1, i32* %3
br label %77
16: ; preds = %2
%17 = call i64 @malloc(i32 808)
%18 = inttoptr i64 %17 to i8**
store i8** %18, i8*** %9
%19 = load i8**, i8*** %9
%20 = icmp eq i8** %19, null
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
store i32 0, i32* %10
br label %26
26: ; preds = %65, %25
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%28 = load i32*, i32** %6
%29 = call i64 @fgets(i8* %27, i32 256, i32* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* %10
%33 = icmp slt i32 %32, 100
br label %34
34: ; preds = %31, %26
%35 = phi i1 [ false, %26 ], [ %33, %31 ]
br i1 %35, label %36, label %68
36: ; preds = %34
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = mul i64 1, %40
%42 = trunc i64 %41 to i32
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to i8*
store i8* %44, i8** %8
%45 = load i8*, i8** %8
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %51
47: ; preds = %36
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %36
%52 = load i8*, i8** %8
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = add nsw i32 %55, 1
%57 = call i32 @strncpy(i8* %52, i8* %53, i32 %56)
%58 = load i8*, i8** %8
%59 = call i32 @chomp(i8* %58)
%60 = load i8*, i8** %8
%61 = load i8**, i8*** %9
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
store i8* %60, i8** %64
br label %65
65: ; preds = %51
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %26
68: ; preds = %34
%69 = load i8**, i8*** %9
%70 = load i32, i32* %10
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8*, i8** %69, i64 %71
store i8* null, i8** %72
%73 = load i8**, i8*** %9
%74 = load i8***, i8**** %5
store i8** %73, i8*** %74
%75 = load i32*, i32** %6
%76 = call i32 @fclose(i32* %75)
store i32 0, i32* %3
br label %77
77: ; preds = %68, %15
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [36 x i8] c"Error allocating memory in get_pig\0A\00"
define i32 @get_pig(i8* nocapture %0, i8*** nocapture writeonly %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %46, label %7
7: ; preds = %2
%8 = tail call i64 @malloc(i32 808)
%9 = inttoptr i64 %8 to i8**
%10 = icmp eq i64 %8, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = call i64 @fgets(i8* %4, i32 256, i32* %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %42, label %18
14: ; preds = %7
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11, %29
%19 = phi i64 [ %35, %29 ], [ 0, %11 ]
%20 = call i32 @strlen(i8* %4)
%21 = add nsw i32 %20, 1
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = icmp eq i64 %22, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %18
%30 = call i32 @strlen(i8* %4)
%31 = add nsw i32 %30, 1
%32 = call i32 @strncpy(i8* %23, i8* %4, i32 %31)
%33 = call i32 @chomp(i8* %23)
%34 = getelementptr inbounds i8*, i8** %9, i64 %19
store i8* %23, i8** %34
%35 = add nuw nsw i64 %19, 1
%36 = call i64 @fgets(i8* %4, i32 256, i32* %5)
%37 = icmp ne i64 %36, 0
%38 = icmp ult i64 %19, 99
%39 = select i1 %37, i1 %38, i1 false
br i1 %39, label %18, label %40
40: ; preds = %29
%41 = and i64 %35, 4294967295
br label %42
42: ; preds = %40, %11
%43 = phi i64 [ 0, %11 ], [ %41, %40 ]
%44 = getelementptr inbounds i8*, i8** %9, i64 %43
store i8* null, i8** %44
store i8** %9, i8*** %1
%45 = call i32 @fclose(i32* %5)
br label %46
46: ; preds = %2, %42
%47 = phi i32 [ 0, %42 ], [ -1, %2 ]
ret i32 %47
}