#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 /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  char str[3][10];
  int i = 0;
  if ((fp = fopen("/Users/chen/outfile", "r")) == NULL) {
    printf("can't open file!\n");
    exit(0);
  }
  while (fgets(str[i], 10, fp) != NULL) {
    printf("%s", str[i]);
    i++;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xe93(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    119c <main+0x4c>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    11a1 <main+0x51>
movslq -0x34(%rbp),%rax
lea    -0x30(%rbp),%rdi
imul   $0xa,%rax,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11f3 <main+0xa3>
movslq -0x34(%rbp),%rax
lea    -0x30(%rbp),%rsi
imul   $0xa,%rax,%rax
add    %rax,%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a1 <main+0x51>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe90(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ea <main+0x8a>
mov    %rax,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11d6 <main+0x76>
lea    0xe73(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xa,%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11b0 <main+0x50>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe28(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"/Users/chen/outfile\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c"can't open file!\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [3 x [10 x i8]]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 0)
unreachable
10: ; preds = %0
br label %11
11: ; preds = %19, %10
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %13
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %14, i64 0, i64 0
%16 = load i32*, i32** %2
%17 = call i32* @fgets(i8* %15, i32 10, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %27
19: ; preds = %11
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %3, i64 0, i64 %21
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %22, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %11
27: ; preds = %11
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"/Users/chen/outfile\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%s\00"
@str = [17 x i8] c"can't open file!\00"
define i32 @main() {
%1 = alloca [3 x [10 x i8]]
%2 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %1, i64 0, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 10, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %19, label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %5, %11
%12 = phi i64 [ %15, %11 ], [ 0, %5 ]
%13 = phi i8* [ %16, %11 ], [ %2, %5 ]
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = add nuw i64 %12, 1
%16 = getelementptr inbounds [3 x [10 x i8]], [3 x [10 x i8]]* %1, i64 0, i64 %15, i64 0
%17 = call i32* @fgets(i8* %16, i32 10, i32* %3)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %11
19: ; preds = %11, %5
%20 = call i32 @fclose(i32* %3)
ret i32 0
}