#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ cpfs_panic(char *, char const *);
int open(char const *, int, int);
int write(int, void *, unsigned int);
void cpfs_debug_fdump(const char *fn, void *p, unsigned size) {
  int fd = open(fn, 2 | 0x0200, 0666);
  if (fd < 0)
    cpfs_panic("cpfs_debug_fdump: can't open '%d'", fn);
  if (((int)size) != write(fd, p, size))
    cpfs_panic("cpfs_debug_fdump: can't write to '%d'", fn);
  close(fd);
}


x86 assembly (clang, -O0):
<cpfs_debug_fdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x202,%esi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1183 <cpfs_debug_fdump+0x43>
mov    -0x8(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1060 <cpfs_panic@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
je     11b5 <cpfs_debug_fdump+0x75>
mov    -0x8(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1060 <cpfs_panic@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpfs_debug_fdump>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x202,%esi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1173 <cpfs_debug_fdump+0x33>
lea    0xe95(%rip),%rdi
mov    %r14,%rsi
call   1060 <cpfs_panic@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
je     1192 <cpfs_debug_fdump+0x52>
lea    0xe98(%rip),%rdi
mov    %r14,%rsi
call   1060 <cpfs_panic@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"cpfs_debug_fdump: can't open '%d'\00"
@.str.1 = [38 x i8] c"cpfs_debug_fdump: can't write to '%d'\00"
define void @cpfs_debug_fdump(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i32 @open(i8* %8, i32 514, i32 438)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = call i32 @cpfs_panic(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %3
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = call i32 @write(i32 %17, i8* %18, i32 %19)
%21 = icmp ne i32 %16, %20
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i8*, i8** %4
%24 = call i32 @cpfs_panic(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %15
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"cpfs_debug_fdump: can't open '%d'\00"
@.str.1 = [38 x i8] c"cpfs_debug_fdump: can't write to '%d'\00"
define void @cpfs_debug_fdump(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @open(i8* %0, i32 514, i32 438)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @cpfs_panic(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %3
%9 = tail call i32 @write(i32 %4, i8* %1, i32 %2)
%10 = icmp eq i32 %9, %2
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @cpfs_panic(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %11, %8
%14 = tail call i32 @close(i32 %4)
ret void
}