#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 O_TRUNC;
int /*<<< orphan*/ S_IRUSR;
int /*<<< orphan*/ close(int);
int open(char const *, int, int /*<<< orphan*/);
int strlen(char const *);
int write(int, char const *, int);
int _prepare_keyfile(const char *name, const char *passphrase) {
  int fd, r;
  fd = open(name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR);
  if (fd != -1) {
    r = write(fd, passphrase, strlen(passphrase));
    close(fd);
  } else
    r = 0;
  return r == strlen(passphrase) ? 0 : 1;
}


x86 assembly (clang, -O0):
<_prepare_keyfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    0x2e94(%rip),%rax
or     (%rax),%esi
mov    0x2e83(%rip),%rax
or     (%rax),%esi
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11bf <_prepare_keyfile+0x7f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
jmp    11c6 <_prepare_keyfile+0x86>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%edx
mov    %eax,%esi
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_prepare_keyfile>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    0x2e8a(%rip),%rax
mov    0x2ea3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1196 <_prepare_keyfile+0x56>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
jmp    1198 <_prepare_keyfile+0x58>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
xor    %ecx,%ecx
cmp    %eax,%ebx
setne  %cl
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
define i32 @_prepare_keyfile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_CREAT
%10 = or i32 %8, %9
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRUSR
%14 = call i32 @open(i8* %7, i32 %12, i32 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* %5
%19 = load i8*, i8** %4
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %5
%24 = call i32 @close(i32 %23)
br label %26
25: ; preds = %2
store i32 0, i32* %6
br label %26
26: ; preds = %25, %17
%27 = load i32, i32* %6
%28 = load i8*, i8** %4
%29 = call i32 @strlen(i8* %28)
%30 = icmp eq i32 %27, %29
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 0, i32 1
ret i32 %32
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
define i32 @_prepare_keyfile(i8* nocapture %0, i8* %1) {
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %4, %3
%6 = load i32, i32* @O_TRUNC
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRUSR
%9 = tail call i32 @open(i8* %0, i32 %7, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = tail call i32 @strlen(i8* %1)
%13 = tail call i32 @write(i32 %9, i8* %1, i32 %12)
%14 = tail call i32 @close(i32 %9)
br label %15
15: ; preds = %2, %11
%16 = phi i32 [ %13, %11 ], [ 0, %2 ]
%17 = tail call i32 @strlen(i8* %1)
%18 = icmp ne i32 %16, %17
%19 = zext i1 %18 to i32
ret i32 %19
}