#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char **, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, ...);
void simple_cat(char *argv[]) {
  write(1, "STATIC\n\n", 8);
  int fd;
  struct stat stat_buffer;
  char file_buffer[2048];
  fd = open(argv[1], O_RDONLY);
  fstat(fd, &stat_buffer);
  read(fd, &file_buffer, stat_buffer.st_size);
  write(1, &file_buffer, stat_buffer.st_size);
  close(fd);
  close(1);
}


x86 assembly (clang, -O0):
<simple_cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%edi
lea    0xe95(%rip),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1070 <fstat@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1050 <read@plt>
mov    -0x10(%rbp),%edx
mov    $0x1,%edi
lea    -0x810(%rbp),%rsi
mov    $0x0,%al
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simple_cat>:
push   %rbp
push   %r14
push   %rbx
sub    $0x810,%rsp
mov    %rdi,%rbx
lea    0xe9b(%rip),%rsi
mov    $0x1,%edi
mov    $0x8,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    0x8(%rbx),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1070 <fstat@plt>
mov    0x8(%rsp),%ebp
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <read@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1040 <close@plt>
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [9 x i8] c"STATIC\0A\0A\00"
@O_RDONLY = global i32 0
define void @simple_cat(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca [2048 x i8]
store i8** %0, i8*** %2
%6 = call i32 (i32, ...) @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%7 = load i8**, i8*** %2
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = call i32 @fstat(i32 %12, %struct.stat* %4)
%14 = load i32, i32* %3
%15 = bitcast [2048 x i8]* %5 to i8**
%16 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @read(i32 %14, i8** %15, i32 %17)
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 (i32, ...) @write(i32 1, [2048 x i8]* %5, i32 %20)
%22 = load i32, i32* %3
%23 = call i32 @close(i32 %22)
%24 = call i32 @close(i32 1)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [9 x i8] c"STATIC\0A\0A\00"
@O_RDONLY = global i32 0
define void @simple_cat(i8** nocapture %0) {
%2 = alloca %struct.stat
%3 = alloca [2048 x i8]
%4 = tail call i32 (i32, ...) @write(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%5 = bitcast %struct.stat* %2 to i8*
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds i8*, i8** %0, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = call i32 @fstat(i32 %10, %struct.stat* %2)
%12 = bitcast [2048 x i8]* %3 to i8**
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @read(i32 %10, i8** %12, i32 %14)
%16 = call i32 (i32, ...) @write(i32 1, [2048 x i8]* %3, i32 %14)
%17 = call i32 @close(i32 %10)
%18 = call i32 @close(i32 1)
ret void
}