#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 */

/* Variables and functions */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int, int);
int /*<<< orphan*/ perror(char const *);
size_t write(int, char const *, size_t);
void writen_file(const char *path, const char *value, size_t count) {
  int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 00644);
  if (fd < 0) {
    perror(path);
    return;
  }
  if (write(fd, value, count) != count) {
    perror(path);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<writen_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
mov    0x2e7f(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1198 <writen_file+0x58>
mov    -0x8(%rbp),%rdi
call   1060 <perror@plt>
jmp    11c3 <writen_file+0x83>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <write@plt>
cmp    -0x18(%rbp),%rax
je     11bb <writen_file+0x7b>
mov    -0x8(%rbp),%rdi
call   1060 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writen_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e7a(%rip),%rcx
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e87(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11a0 <writen_file+0x60>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <write@plt>
cmp    %rbx,%rax
jne    11b2 <writen_file+0x72>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <close@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <perror@plt>
mov    %r14,%rdi
call   1060 <perror@plt>
jmp    118f <writen_file+0x4f>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @writen_file(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 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %9, %10
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = call i32 @open(i8* %8, i32 %13, i32 420)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = call i32 @perror(i8* %18)
br label %33
20: ; preds = %3
%21 = load i32, i32* %7
%22 = load i8*, i8** %5
%23 = load i64, i64* %6
%24 = call i64 @write(i32 %21, i8* %22, i64 %23)
%25 = load i64, i64* %6
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i8*, i8** %4
%29 = call i32 @perror(i8* %28)
br label %30
30: ; preds = %27, %20
%31 = load i32, i32* %7
%32 = call i32 @close(i32 %31)
br label %33
33: ; preds = %30, %17
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define void @writen_file(i8* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* %0, i32 %8, i32 420)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @perror(i8* %0)
br label %20
13: ; preds = %3
%14 = tail call i64 @write(i32 %9, i8* %1, i64 %2)
%15 = icmp eq i64 %14, %2
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 @perror(i8* %0)
br label %18
18: ; preds = %16, %13
%19 = tail call i32 @close(i32 %9)
br label %20
20: ; preds = %18, %11
ret void
}