#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 *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int serialsave(const char *snfilename, unsigned char *serialnumber) {
  FILE *fsn;
  if (serialnumber) {
    fsn = fopen(snfilename, "wb+");
    if (!fsn)
      return -1;
    fwrite(serialnumber, sizeof(unsigned char), 64, fsn);
    fclose(fsn);
    return 0;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<serialsave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a2 <serialsave+0x72>
mov    -0x10(%rbp),%rdi
lea    0xeaa(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1176 <serialsave+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a9 <serialsave+0x79>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40,%edx
call   1050 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <serialsave+0x79>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialsave>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebp
test   %rsi,%rsi
je     1174 <serialsave+0x44>
mov    %rsi,%rbx
lea    0xeb8(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1174 <serialsave+0x44>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x40,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"wb+\00"
define i32 @serialsave(i8* nocapture %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @fwrite(i8* %1, i32 1, i32 64, i32* %5)
%9 = tail call i32 @fclose(i32* %5)
br label %10
10: ; preds = %2, %4, %7
%11 = phi i32 [ 0, %7 ], [ -1, %4 ], [ -1, %2 ]
ret i32 %11
}