#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 fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char const *, char *);
int cat(const char *file_name) {
  FILE *ip_file = !strcmp(file_name, "-") ? stdin : fopen(file_name, "r");
  char ch = 0;
  if (NULL == ip_file) {
    perror(file_name);
    return 1;
  }
  while (-1 != (ch = fgetc(ip_file))) {
    fputc(ch, stdout);
  }
  return strcmp(file_name, "-") ? fclose(ip_file) : 0;
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1199 <cat+0x39>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11ad <cat+0x4d>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11da <cat+0x7a>
mov    -0x10(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    124f <cat+0xef>
jmp    11df <cat+0x7f>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1214 <cat+0xb4>
mov    -0x19(%rbp),%al
mov    0x2dd3(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    11df <cat+0x7f>
mov    -0x10(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     123f <cat+0xdf>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x2c(%rbp)
jmp    1249 <cat+0xe9>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    1249 <cat+0xe9>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xe91(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e8 <cat+0x88>
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     11f7 <cat+0x97>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0xff,%al
je     11c7 <cat+0x67>
mov    0x2e35(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0xff,%al
jne    11b0 <cat+0x50>
lea    0xe32(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1206 <cat+0xa6>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    1190 <cat+0x30>
mov    %r14,%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    1208 <cat+0xa8>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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