#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdout;
void showfile(char *filename) {
  FILE *fp;
  char buffer[80];
  int row = 0;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    perror(filename);
    return;
  }
  while (fgets(buffer, sizeof(buffer), fp) != NULL) {
    fputs(buffer, stdout);
    if (row++ > 24 - 3) {
      getchar();
      row = 0;
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<showfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a0 <showfile+0x40>
mov    -0x8(%rbp),%rdi
call   1080 <perror@plt>
jmp    1203 <showfile+0xa3>
jmp    11a5 <showfile+0x45>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11fa <showfile+0x9a>
lea    -0x60(%rbp),%rdi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    -0x64(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x64(%rbp)
cmp    $0x15,%eax
jle    11f5 <showfile+0x95>
mov    $0x0,%al
call   1060 <getchar@plt>
movl   $0x0,-0x64(%rbp)
jmp    11a5 <showfile+0x45>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11f6 <showfile+0x96>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11e3 <showfile+0x83>
xor    %ebp,%ebp
mov    0x2e41(%rip),%r15
mov    %rsp,%rbx
jmp    11ce <showfile+0x6e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11e3 <showfile+0x83>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
cmp    $0x16,%ebp
jge    11b0 <showfile+0x50>
add    $0x1,%ebp
jmp    11b9 <showfile+0x59>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <perror@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
define void @showfile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [80 x i8]
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @perror(i8* %11)
br label %32
13: ; preds = %1
br label %14
14: ; preds = %28, %13
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i32* @fgets(i8* %15, i32 80, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* @stdout
%22 = call i32 @fputs(i8* %20, i32 %21)
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
%25 = icmp sgt i32 %23, 21
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = call i32 (...) @getchar()
store i32 0, i32* %5
br label %28
28: ; preds = %26, %19
br label %14
29: ; preds = %14
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
br label %32
32: ; preds = %29, %10
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stdout = global i32 0
define void @showfile(i8* nocapture %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = call i32* @fgets(i8* %3, i32 80, i32* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %23, label %11
9: ; preds = %1
%10 = tail call i32 @perror(i8* %0)
br label %25
11: ; preds = %6, %19
%12 = phi i32 [ %20, %19 ], [ 0, %6 ]
%13 = load i32, i32* @stdout
%14 = call i32 @fputs(i8* %3, i32 %13)
%15 = add nsw i32 %12, 1
%16 = icmp sgt i32 %12, 21
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 (...) @getchar()
br label %19
19: ; preds = %17, %11
%20 = phi i32 [ 0, %17 ], [ %15, %11 ]
%21 = call i32* @fgets(i8* %3, i32 80, i32* %4)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %11
23: ; preds = %19, %6
%24 = call i32 @fclose(i32* %4)
br label %25
25: ; preds = %23, %9
ret void
}