#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void cat(char *command) {
  FILE *file;
  file = fopen((const char *)command, "r");
  if (file == NULL) {
    printf("Error, file doesn't exists\n");
    return;
  }
  char *buffer = (char *)malloc(sizeof(char) * 2048);
  while (fgets(buffer, 2048, file))
    printf("%s", buffer);
  fclose(file);
  free(buffer);
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119e <cat+0x3e>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f1 <cat+0x91>
mov    $0x800,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11df <cat+0x7f>
mov    -0x18(%rbp),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ac <cat+0x4c>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat>:
push   %r15
push   %r14
push   %rbx
lea    0xe84(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11f7 <cat+0x87>
mov    %rax,%r14
mov    $0x800,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     11e2 <cat+0x72>
lea    0xe50(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    11c0 <cat+0x50>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xe07(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [28 x i8] c"Error, file doesn't exists\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define void @cat(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %27
11: ; preds = %1
%12 = call i64 @malloc(i32 2048)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %4
br label %14
14: ; preds = %19, %11
%15 = load i8*, i8** %4
%16 = load i32*, i32** %3
%17 = call i64 @fgets(i8* %15, i32 2048, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %14
22: ; preds = %14
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
%25 = load i8*, i8** %4
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %22, %9
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@str = [27 x i8] c"Error, file doesn't exists\00"
define void @cat(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %18
6: ; preds = %1
%7 = tail call i64 @malloc(i32 2048)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 @fgets(i8* %8, i32 2048, i32* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6, %11
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%13 = tail call i64 @fgets(i8* %8, i32 2048, i32* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %11
15: ; preds = %11, %6
%16 = tail call i32 @fclose(i32* %2)
%17 = tail call i32 @free(i8* %8)
br label %18
18: ; preds = %15, %4
ret void
}