#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*/ LOG(char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fwrite(void const *, size_t, int, int /*<<< orphan*/ *);
void dumpbin(const char *path, const void *data, size_t cnt) {
  FILE *f = fopen(path, "wb+");
  if (f) {
    fwrite(data, cnt, 1, f);
    fflush(f);
    fclose(f);
  } else
    LOG("Error saving file '%s'\n", path);
}


x86 assembly (clang, -O0):
<dumpbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b0 <dumpbin+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fflush@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11c0 <dumpbin+0x70>
mov    -0x8(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1050 <LOG@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpbin>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a3 <dumpbin+0x53>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fflush@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fclose@plt>
lea    0xe5a(%rip),%rdi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <LOG@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"wb+\00"
@.str.1 = [24 x i8] c"Error saving file '%s'\0A\00"
define void @dumpbin(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i64, i64* %6
%15 = load i32*, i32** %7
%16 = call i32 @fwrite(i8* %13, i64 %14, i32 1, i32* %15)
%17 = load i32*, i32** %7
%18 = call i32 @fflush(i32* %17)
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
br label %24
21: ; preds = %3
%22 = load i8*, i8** %4
%23 = call i32 @LOG(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %12
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"wb+\00"
@.str.1 = [24 x i8] c"Error saving file '%s'\0A\00"
define void @dumpbin(i8* %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i32 @fwrite(i8* %1, i64 %2, i32 1, i32* %4)
%8 = tail call i32 @fflush(i32* %4)
%9 = tail call i32 @fclose(i32* %4)
br label %12
10: ; preds = %3
%11 = tail call i32 @LOG(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %10, %6
ret void
}