#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
void cat(FILE *fp) {
  char buffer[4096];
  rewind(fp);
  while (fgets(buffer, sizeof(buffer), fp) != NULL) {
    printf("%s\n\n", buffer);
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     119d <cat+0x5d>
lea    -0x1010(%rbp),%rsi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    1158 <cat+0x18>
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%r15
call   1040 <rewind@plt>
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11a9 <cat+0x69>
lea    0xe8e(%rip),%r14
mov    %rsp,%rbx
mov    0x2e64(%rip),%r12
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    (%r12),%edi
call   1060 <fflush@plt>
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1180 <cat+0x40>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s\0A\0A\00"
@stdout = global i32 0
define void @cat(i32* %0) {
%2 = alloca i32*
%3 = alloca [4096 x i8]
store i32* %0, i32** %2
%4 = load i32*, i32** %2
%5 = call i32 @rewind(i32* %4)
br label %6
6: ; preds = %11, %1
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = load i32*, i32** %2
%9 = call i32* @fgets(i8* %7, i32 4096, i32* %8)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%13 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @stdout
%15 = call i32 @fflush(i32 %14)
br label %6
16: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s\0A\0A\00"
@stdout = global i32 0
define void @cat(i32* nocapture %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @rewind(i32* %0)
%5 = call i32* @fgets(i8* %3, i32 4096, i32* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %13, label %7
7: ; preds = %1, %7
%8 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3)
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
%11 = call i32* @fgets(i8* %3, i32 4096, i32* %0)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %7
13: ; preds = %7, %1
ret void
}