#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 */
scalar_t__ EOF;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
void Save(char *filename, char *buffer, int length) {
  FILE *fp;
  if ((fp = fopen(filename, "wb")) == NULL) {
    printf("\nFile create error\n");
    exit(-1);
  };
  if (fwrite(buffer, 1, length, fp) != length) {
    printf("\nFile write error\n");
    exit(-1);
  };
  if (fclose(fp) == EOF) {
    printf("\nFile close error\n");
    exit(-1);
  };
}


x86 assembly (clang, -O0):
<Save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1197 <Save+0x47>
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
cmp    -0x14(%rbp),%eax
je     11cb <Save+0x7b>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%rax
jne    11fa <Save+0xaa>
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Save>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
lea    0xea0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     119c <Save+0x4c>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
cmp    %ebp,%eax
jne    11a5 <Save+0x55>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%rax
je     11ae <Save+0x5e>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe84(%rip),%rdi
jmp    11b5 <Save+0x65>
lea    0xe69(%rip),%rdi
jmp    11b5 <Save+0x65>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [20 x i8] c"\0AFile create error\0A\00"
@.str.2 = [19 x i8] c"\0AFile write error\0A\00"
@EOF = global i64 0
@.str.3 = [19 x i8] c"\0AFile close error\0A\00"
define void @Save(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* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = load i32*, i32** %7
%18 = call i32 @fwrite(i8* %15, i32 1, i32 %16, i32* %17)
%19 = load i32, i32* %6
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %14
%25 = load i32*, i32** %7
%26 = call i64 @fclose(i32* %25)
%27 = load i64, i64* @EOF
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %24
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@EOF = global i64 0
@str = [18 x i8] c"\0AFile close error\00"
@str.4 = [18 x i8] c"\0AFile write error\00"
@str.5 = [19 x i8] c"\0AFile create error\00"
define void @Save(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %3
%10 = tail call i32 @fwrite(i8* %1, i32 1, i32 %2, i32* %4)
%11 = icmp eq i32 %10, %2
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %9
%16 = tail call i64 @fclose(i32* %4)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %15
ret void
}