#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int output_file(char *fpath) {
  FILE *fp = fopen(fpath, "r");
  char line[100 + 1];
  int line_num = 0;
  if (fp == NULL) {
    return 1;
  }
  while (fgets(line, 100, fp) != NULL) {
    printf("%s", line);
    line_num++;
    if (line_num == 20) {
      line_num = 0;
    }
  }
  while (line_num > 0 && line_num < 20) {
    printf("\n");
    line_num++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<output_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x84(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1174 <output_file+0x44>
movl   $0x1,-0x4(%rbp)
jmp    1238 <output_file+0x108>
jmp    1179 <output_file+0x49>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11d2 <output_file+0xa2>
lea    -0x80(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
cmpl   $0x14,-0x84(%rbp)
jne    11cd <output_file+0x9d>
movl   $0x0,-0x84(%rbp)
jmp    1179 <output_file+0x49>
jmp    11d7 <output_file+0xa7>
xor    %eax,%eax
cmpl   $0x0,-0x84(%rbp)
mov    %al,-0x85(%rbp)
jle    11fc <output_file+0xcc>
cmpl   $0x14,-0x84(%rbp)
setl   %al
mov    %al,-0x85(%rbp)
mov    -0x85(%rbp),%al
test   $0x1,%al
jne    120f <output_file+0xdf>
jmp    1231 <output_file+0x101>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11d7 <output_file+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e0 <output_file+0xa0>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11e7 <output_file+0xa7>
xor    %r12d,%r12d
lea    0xe7f(%rip),%r14
mov    %rsp,%rbp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0x14,%ebx
cmove  %r12d,%ebx
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1190 <output_file+0x50>
lea    -0x1(%rbx),%eax
xor    %ebp,%ebp
cmp    $0x12,%eax
ja     11e9 <output_file+0xa9>
add    $0xffffffec,%ebx
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
inc    %ebx
jne    11d0 <output_file+0x90>
jmp    11e9 <output_file+0xa9>
mov    $0x1,%ebp
jmp    11e9 <output_file+0xa9>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @output_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [101 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
store i32 0, i32* %6
%9 = load i32*, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %41
12: ; preds = %1
br label %13
13: ; preds = %26, %12
%14 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i32* @fgets(i8* %14, i32 100, i32* %15)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 20
br i1 %24, label %25, label %26
25: ; preds = %18
store i32 0, i32* %6
br label %26
26: ; preds = %25, %18
br label %13
27: ; preds = %13
br label %28
28: ; preds = %36, %27
%29 = load i32, i32* %6
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 20
br label %34
34: ; preds = %31, %28
%35 = phi i1 [ false, %28 ], [ %33, %31 ]
br i1 %35, label %36, label %40
36: ; preds = %34
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %28
40: ; preds = %34
store i32 0, i32* %2
br label %41
41: ; preds = %40, %11
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @output_file(i8* nocapture %0) {
%2 = alloca [101 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [101 x i8], [101 x i8]* %2, i64 0, i64 0
%5 = icmp eq i32* %3, null
br i1 %5, label %25, label %6
6: ; preds = %1
%7 = call i32* @fgets(i8* %4, i32 100, i32* %3)
%8 = icmp eq i32* %7, null
br i1 %8, label %25, label %12
9: ; preds = %12
%10 = add i32 %17, -1
%11 = icmp ult i32 %10, 19
br i1 %11, label %20, label %25
12: ; preds = %6, %12
%13 = phi i32 [ %17, %12 ], [ 0, %6 ]
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%15 = add nsw i32 %13, 1
%16 = icmp eq i32 %15, 20
%17 = select i1 %16, i32 0, i32 %15
%18 = call i32* @fgets(i8* %4, i32 100, i32* %3)
%19 = icmp eq i32* %18, null
br i1 %19, label %9, label %12
20: ; preds = %9, %20
%21 = phi i32 [ %23, %20 ], [ %17, %9 ]
%22 = call i32 @putchar(i32 10)
%23 = add i32 %21, 1
%24 = icmp eq i32 %23, 20
br i1 %24, label %25, label %20
25: ; preds = %20, %6, %9, %1
%26 = phi i32 [ 1, %1 ], [ 0, %9 ], [ 0, %6 ], [ 0, %20 ]
ret i32 %26
}