#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ putchar(int);
int cat(char *filename, int overhead) {
  int c;
  int i = 0;
  FILE *file;
  file = fopen(filename, "r");
  if (file) {
    while ((c = fgetc(file)) != EOF) {
      if (overhead > 0) {
        overhead--;
        continue;
      }
      if (c == '\n')
        c = '\t';
      putchar(c);
      i++;
    }
    fclose(file);
  } else
    return -1;
  return i;
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e2 <cat+0xa2>
jmp    117a <cat+0x3a>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e5b(%rip),%rcx
cmp    (%rcx),%eax
je     11d4 <cat+0x94>
cmpl   $0x0,-0x14(%rbp)
jle    11ad <cat+0x6d>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    117a <cat+0x3a>
cmpl   $0xa,-0x18(%rbp)
jne    11be <cat+0x7e>
movl   $0x9,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <cat+0x3a>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11ee <cat+0xae>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <cat+0xb4>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     117f <cat+0x3f>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e7a(%rip),%r15
xor    %ebp,%ebp
cmp    (%r15),%eax
jne    118f <cat+0x4f>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1184 <cat+0x44>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x9,%r12d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
test   %r14d,%r14d
jg     11d0 <cat+0x90>
cmp    $0xa,%eax
cmove  %r12d,%eax
mov    %eax,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%eax
jne    11a0 <cat+0x60>
jmp    1175 <cat+0x35>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffff,%r14d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
xor    %ebp,%ebp
cmp    (%r15),%eax
jne    1195 <cat+0x55>
jmp    1175 <cat+0x35>

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @cat(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %32, label %5
5: ; preds = %2
%6 = tail call i32 @fgetc(i32* %3)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %29, label %9
9: ; preds = %5, %16
%10 = phi i32 [ %18, %16 ], [ %6, %5 ]
%11 = phi i32 [ %17, %16 ], [ %1, %5 ]
%12 = icmp sgt i32 %11, 0
br label %13
13: ; preds = %9, %21
%14 = phi i32 [ %10, %9 ], [ %26, %21 ]
%15 = phi i32 [ 0, %9 ], [ %25, %21 ]
br i1 %12, label %16, label %21
16: ; preds = %13
%17 = add nsw i32 %11, -1
%18 = tail call i32 @fgetc(i32* %3)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %29, label %9
21: ; preds = %13
%22 = icmp eq i32 %14, 10
%23 = select i1 %22, i32 9, i32 %14
%24 = tail call i32 @putchar(i32 %23)
%25 = add nuw nsw i32 %15, 1
%26 = tail call i32 @fgetc(i32* %3)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %13
29: ; preds = %16, %21, %5
%30 = phi i32 [ 0, %5 ], [ %25, %21 ], [ 0, %16 ]
%31 = tail call i32 @fclose(i32* %3)
br label %32
32: ; preds = %2, %29
%33 = phi i32 [ %30, %29 ], [ -1, %2 ]
ret i32 %33
}