#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_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ strlen(char const *);
int stub1(char const *, int, ...);
int /*<<< orphan*/ write(int, char const *, int /*<<< orphan*/);
int create_file(int (*ofunc)(char const *, int, ...), char const *name,
                char const *data) {
  int fd;
  if ((fd = (*ofunc)(name, O_WRONLY | O_CREAT, 0666)) == -1) {
    perror(name);
    return -1;
  }
  write(fd, data, strlen(data));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    0x2e8c(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   *%rcx
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1198 <create_file+0x58>
mov    -0x18(%rbp),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <create_file+0x8c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rcx
mov    0x2e79(%rip),%rax
mov    0x2e9a(%rip),%rdx
mov    (%rdx),%esi
or     (%rax),%esi
xor    %r14d,%r14d
mov    %r15,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   *%rcx
cmp    $0xffffffff,%eax
je     11a1 <create_file+0x61>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1193 <create_file+0x53>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @create_file(i32 (i8*, i32, ...)* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32 (i8*, i32, ...)*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 (i8*, i32, ...)* %0, i32 (i8*, i32, ...)** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i32 (i8*, i32, ...)*, i32 (i8*, i32, ...)** %5
%10 = load i8*, i8** %6
%11 = load i32, i32* @O_WRONLY
%12 = load i32, i32* @O_CREAT
%13 = or i32 %11, %12
%14 = call i32 (i8*, i32, ...) %9(i8* %10, i32 %13, i32 438)
store i32 %14, i32* %8
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = call i32 @perror(i8* %17)
store i32 -1, i32* %4
br label %27
19: ; preds = %3
%20 = load i32, i32* %8
%21 = load i8*, i8** %7
%22 = load i8*, i8** %7
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @write(i32 %20, i8* %21, i32 %23)
%25 = load i32, i32* %8
%26 = call i32 @close(i32 %25)
store i32 0, i32* %4
br label %27
27: ; preds = %19, %16
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @create_file(i32 (i8*, i32, ...)* nocapture %0, i8* %1, i8* %2) {
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = tail call i32 (i8*, i32, ...) %0(i8* %1, i32 %6, i32 438)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @perror(i8* %1)
br label %15
11: ; preds = %3
%12 = tail call i32 @strlen(i8* %2)
%13 = tail call i32 @write(i32 %7, i8* %2, i32 %12)
%14 = tail call i32 @close(i32 %7)
br label %15
15: ; preds = %11, %9
%16 = phi i32 [ -1, %9 ], [ 0, %11 ]
ret i32 %16
}