#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_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ write(int, char *, size_t);
int jnb_io_write(char *filename, char *data, size_t data_size) {
  int fd = open(filename, O_RDWR | O_CREAT | 0, 0644);
  if (!fd) {
    perror("open()");
    return -1;
  }
  write(fd, data, data_size);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<jnb_io_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
or     $0x0,%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    119c <jnb_io_write+0x5c>
lea    0xe75(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <jnb_io_write+0x7b>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jnb_io_write>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    0x2e8f(%rip),%rax
mov    0x2ea0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
test   %eax,%eax
je     1187 <jnb_io_write+0x47>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe72(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    1182 <jnb_io_write+0x42>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [7 x i8] c"open()\00"
define i32 @jnb_io_write(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i8*, i8** %5
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = or i32 %12, 0
%14 = call i32 @open(i8* %9, i32 %13, i32 420)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp ne i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %3
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %26
19: ; preds = %3
%20 = load i32, i32* %8
%21 = load i8*, i8** %6
%22 = load i64, i64* %7
%23 = call i32 @write(i32 %20, i8* %21, i64 %22)
%24 = load i32, i32* %8
%25 = call i32 @close(i32 %24)
store i32 0, i32* %4
br label %26
26: ; preds = %19, %17
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [7 x i8] c"open()\00"
define i32 @jnb_io_write(i8* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6, i32 420)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %14
11: ; preds = %3
%12 = tail call i32 @write(i32 %7, i8* %1, i64 %2)
%13 = tail call i32 @close(i32 %7)
br label %14
14: ; preds = %11, %9
%15 = phi i32 [ 0, %11 ], [ -1, %9 ]
ret i32 %15
}