#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*/ fu_Close(int /*<<< orphan*/ *);
int fu_Fnwrite(int /*<<< orphan*/ *, char const *, int);
int /*<<< orphan*/ *fu_Open(char const *, char *);
int fu_Nwrite(const char *path, const char *buffer, int length) {
  int count;
  FILE *stream = fu_Open(path, "w");
  if (NULL == stream)
    return -1;
  count = fu_Fnwrite(stream, buffer, length);
  fu_Close(stream);
  return count;
}


x86 assembly (clang, -O0):
<fu_Nwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1050 <fu_Open@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    116f <fu_Nwrite+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1191 <fu_Nwrite+0x61>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <fu_Fnwrite@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fu_Close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fu_Nwrite>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
lea    0xebf(%rip),%rsi
call   1050 <fu_Open@plt>
test   %rax,%rax
je     116a <fu_Nwrite+0x3a>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <fu_Fnwrite@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <fu_Close@plt>
mov    %ebx,%eax
jmp    116f <fu_Nwrite+0x3f>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
define i32 @fu_Nwrite(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32* @fu_Open(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @fu_Fnwrite(i32* %4, i8* %1, i32 %2)
%8 = tail call i32 @fu_Close(i32* %4)
br label %9
9: ; preds = %3, %6
%10 = phi i32 [ %7, %6 ], [ -1, %3 ]
ret i32 %10
}