#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 */

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void cat(int dfd, char *src) {
  char buf[BUFSIZ];
  int n, fd;
  if ((fd = open(src, O_RDONLY)) == -1)
    return;
  while ((n = read(fd, buf, sizeof buf)) > 0)
    write(dfd, buf, n);
  close(fd);
}


x86 assembly (clang, -O0):
<cat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    11a9 <cat+0x69>
movl   $0x1,-0x2c(%rbp)
jmp    11ef <cat+0xaf>
jmp    11ae <cat+0x6e>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    -0x28(%rbp),%edi
mov    %eax,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    11e0 <cat+0xa0>
mov    -0x38(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    -0x24(%rbp),%edx
call   1030 <write@plt>
jmp    11ae <cat+0x6e>
mov    -0x28(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rax
mov    %edi,%r14d
mov    0x2e80(%rip),%rcx
mov    (%rcx),%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    0x2e75(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11c5 <cat+0x85>
mov    %eax,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11b1 <cat+0x71>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1190 <cat+0x50>
mov    %r12d,%edi
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@O_RDONLY = global i32 0
define void @cat(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
%14 = load i8*, i8** %4
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %8
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %2
store i32 1, i32* %9
br label %32
19: ; preds = %2
br label %20
20: ; preds = %25, %19
%21 = load i32, i32* %8
%22 = trunc i64 %11 to i32
%23 = call i32 @read(i32 %21, i8* %13, i32 %22)
store i32 %23, i32* %7
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* %3
%27 = load i32, i32* %7
%28 = call i32 @write(i32 %26, i8* %13, i32 %27)
br label %20
29: ; preds = %20
%30 = load i32, i32* %8
%31 = call i32 @close(i32 %30)
store i32 0, i32* %9
br label %32
32: ; preds = %29, %18
%33 = load i8*, i8** %5
%34 = load i32, i32* %9
switch i32 %34, label %36 [
i32 0, label %35
i32 1, label %35
]
35: ; preds = %32, %32
ret void
36: ; preds = %32
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@O_RDONLY = global i32 0
define void @cat(i32 %0, i8* nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %1, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %19, label %9
9: ; preds = %2
%10 = call i32 @read(i32 %7, i8* %5, i32 %3)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9, %12
%13 = phi i32 [ %15, %12 ], [ %10, %9 ]
%14 = call i32 @write(i32 %0, i8* %5, i32 %13)
%15 = call i32 @read(i32 %7, i8* %5, i32 %3)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %12, label %17
17: ; preds = %12, %9
%18 = tail call i32 @close(i32 %7)
br label %19
19: ; preds = %2, %17
ret void
}