#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*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/ *);
int myfoo(int, char **);
int /*<<< orphan*/ stderr;
int main() {
  char *argv[3];
  char *name = "myfoo";
  size_t dummy;
  FILE *fp = fopen("testcase", "r");
  if (!fp) {
    fprintf(stderr, "Could not find a testfile\n");
    exit(1);
  }
  argv[0] = name;
  argv[1] = NULL;
  argv[2] = NULL;
  getline(&(argv[1]), &dummy, fp);
  getline(&(argv[2]), &dummy, fp);
  return (myfoo(3, argv));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe95(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11ab <main+0x5b>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
mov    -0x38(%rbp),%rdx
lea    -0x30(%rbp),%rsi
call   1060 <getline@plt>
lea    -0x20(%rbp),%rdi
add    $0x10,%rdi
mov    -0x38(%rbp),%rdx
lea    -0x30(%rbp),%rsi
call   1060 <getline@plt>
lea    -0x20(%rbp),%rsi
mov    $0x3,%edi
call   1040 <myfoo@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xea6(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c6 <main+0x76>
mov    %rax,%rbx
lea    0xe85(%rip),%rax
mov    %rax,(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%r14
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
lea    0x18(%rsp),%r15
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <getline@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <getline@plt>
mov    %rsp,%rsi
mov    $0x3,%edi
call   1040 <myfoo@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"myfoo\00"
@.str.1 = [9 x i8] c"testcase\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"Could not find a testfile\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i8*]
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
store i32 0, i32* %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i8*, i8** %3
%15 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
store i8* %14, i8** %15
%16 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 1
store i8* null, i8** %16
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 2
store i8* null, i8** %17
%18 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 1
%19 = load i32*, i32** %5
%20 = call i32 @getline(i8** %18, i64* %4, i32* %19)
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 2
%22 = load i32*, i32** %5
%23 = call i32 @getline(i8** %21, i64* %4, i32* %22)
%24 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%25 = call i32 @myfoo(i32 3, i8** %24)
ret i32 %25
}

LLVM IR (-O2):
@.str = [6 x i8] c"myfoo\00"
@.str.1 = [9 x i8] c"testcase\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"Could not find a testfile\0A\00"
define i32 @main() {
%1 = alloca [3 x i8*]
%2 = alloca i64
%3 = bitcast [3 x i8*]* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 1
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 2
%15 = bitcast i8** %13 to i8*
%16 = call i32 @getline(i8** %13, i64* %2, i32* %5)
%17 = call i32 @getline(i8** %14, i64* %2, i32* %5)
%18 = call i32 @myfoo(i32 3, i8** %12)
ret i32 %18
}