#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fwrite(char const *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int File_Save(const char *fileName, const char *buffer, size_t size) {
  ((void)0);
  FILE *file;
  size_t result;
  if (!fileName || !buffer || !size)
    return 0;
  file = fopen(fileName, "wb");
  if (!file) {
    printf("File_Save: Could not open file %s (fopen)", fileName);
    return 0;
  }
  result = fwrite(buffer, sizeof(char), size, file);
  if (result != size) {
    fclose(file);
    printf("File_Save: Could not write the same number of bytes (size != "
           "result) for file %s (size %u, result %u)",
           fileName, size, result);
    return 0;
  }
  fclose(file);
  return 1;
}


x86 assembly (clang, -O0):
<File_Save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1175 <File_Save+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1175 <File_Save+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    1181 <File_Save+0x41>
movl   $0x0,-0x4(%rbp)
jmp    1225 <File_Save+0xe5>
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11be <File_Save+0x7e>
mov    -0x10(%rbp),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1225 <File_Save+0xe5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     1215 <File_Save+0xd5>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1225 <File_Save+0xe5>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<File_Save>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
test   %rdi,%rdi
je     11d4 <File_Save+0x94>
mov    %rsi,%rbp
test   %rsi,%rsi
je     11d4 <File_Save+0x94>
mov    %rdx,%r14
test   %rdx,%rdx
je     11d4 <File_Save+0x94>
mov    %rdi,%r12
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c0 <File_Save+0x80>
mov    %rax,%rbx
mov    $0x1,%r15d
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    %r14,%rbp
je     11d4 <File_Save+0x94>
lea    0xe82(%rip),%rdi
xor    %r15d,%r15d
mov    %r12,%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d4 <File_Save+0x94>
lea    0xe3c(%rip),%rdi
xor    %r15d,%r15d
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [42 x i8] c"File_Save: Could not open file %s (fopen)\00"
@.str.2 = [102 x i8] c"File_Save: Could not write the same number of bytes (size != result) for file %s (size %u, result %u)\00"
define i32 @File_Save(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i64, i64* %7
%17 = icmp ne i64 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %15, %12, %3
store i32 0, i32* %4
br label %45
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %8
%22 = load i32*, i32** %8
%23 = icmp ne i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 0, i32* %4
br label %45
27: ; preds = %19
%28 = load i8*, i8** %6
%29 = load i64, i64* %7
%30 = load i32*, i32** %8
%31 = call i64 @fwrite(i8* %28, i32 1, i64 %29, i32* %30)
store i64 %31, i64* %9
%32 = load i64, i64* %9
%33 = load i64, i64* %7
%34 = icmp ne i64 %32, %33
br i1 %34, label %35, label %42
35: ; preds = %27
%36 = load i32*, i32** %8
%37 = call i32 @fclose(i32* %36)
%38 = load i8*, i8** %5
%39 = load i64, i64* %7
%40 = load i64, i64* %9
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.2, i64 0, i64 0), i8* %38, i64 %39, i64 %40)
store i32 0, i32* %4
br label %45
42: ; preds = %27
%43 = load i32*, i32** %8
%44 = call i32 @fclose(i32* %43)
store i32 1, i32* %4
br label %45
45: ; preds = %42, %35, %24, %18
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [42 x i8] c"File_Save: Could not open file %s (fopen)\00"
@.str.2 = [102 x i8] c"File_Save: Could not write the same number of bytes (size != result) for file %s (size %u, result %u)\00"
define i32 @File_Save(i8* %0, i8* %1, i64 %2) {
%4 = icmp ne i8* %0, null
%5 = icmp ne i8* %1, null
%6 = and i1 %4, %5
%7 = icmp ne i64 %2, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
14: ; preds = %9
%15 = tail call i64 @fwrite(i8* %1, i32 1, i64 %2, i32* %10)
%16 = icmp eq i64 %15, %2
%17 = tail call i32 @fclose(i32* %10)
br i1 %16, label %20, label %18
18: ; preds = %14
%19 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.2, i64 0, i64 0), i8* %0, i64 %2, i64 %15)
br label %20
20: ; preds = %14, %3, %18, %12
%21 = phi i32 [ 0, %18 ], [ 0, %12 ], [ 0, %3 ], [ 1, %14 ]
ret i32 %21
}