#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 S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fdatasync(int);
int open_or_die_m(char const *, int, int);
int write_or_die(int, void const *, size_t);
int write_blob_or_die(const char *file, const void *blob, size_t count) {
  int fd, ret;
  fd = open_or_die_m(file, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
  ret = write_or_die(fd, blob, count);
  fdatasync(fd);
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<write_blob_or_die>:
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    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
mov    0x2e7f(%rip),%rax
or     (%rax),%esi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
mov    0x2e55(%rip),%rax
or     (%rax),%edx
call   1040 <open_or_die_m@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <write_or_die@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <fdatasync@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_blob_or_die>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    0x2e67(%rip),%rax
mov    0x2ea0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e8d(%rip),%rax
or     (%rax),%esi
mov    0x2e5c(%rip),%rax
mov    0x2e65(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1040 <open_or_die_m@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <write_or_die@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <fdatasync@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @write_blob_or_die(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRUSR
%16 = load i32, i32* @S_IWUSR
%17 = or i32 %15, %16
%18 = call i32 @open_or_die_m(i8* %9, i32 %14, i32 %17)
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i8*, i8** %5
%21 = load i64, i64* %6
%22 = call i32 @write_or_die(i32 %19, i8* %20, i64 %21)
store i32 %22, i32* %8
%23 = load i32, i32* %7
%24 = call i32 @fdatasync(i32 %23)
%25 = load i32, i32* %7
%26 = call i32 @close(i32 %25)
%27 = load i32, i32* %8
ret i32 %27
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
define i32 @write_blob_or_die(i8* %0, i8* %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 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %10, %9
%12 = tail call i32 @open_or_die_m(i8* %0, i32 %8, i32 %11)
%13 = tail call i32 @write_or_die(i32 %12, i8* %1, i64 %2)
%14 = tail call i32 @fdatasync(i32 %12)
%15 = tail call i32 @close(i32 %12)
ret i32 %13
}