#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 /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ cover_start();
int /*<<< orphan*/ cover_stop();
int /*<<< orphan*/ fail(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char const *, long);
void binfmt(const char *data, long size) {
  static int fd = -1;
  if (fd == -1)
    fd = open("/proc/sys/fs/binfmt_misc/register", O_WRONLY);
  if (fd == -1)
    fail("open(/proc/sys/fs/binfmt_misc/register) failed");
  cover_start();
  write(fd, data, size);
  cover_stop();
}


x86 assembly (clang, -O0):
<binfmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0xffffffff,0x2ee1(%rip)
jne    1188 <binfmt+0x38>
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    0xe83(%rip),%rdi
call   1060 <open@plt>
mov    %eax,0x2ec0(%rip)
cmpl   $0xffffffff,0x2eb9(%rip)
jne    11a1 <binfmt+0x51>
lea    0xe86(%rip),%rdi
call   1040 <fail@plt>
mov    $0x0,%al
call   1050 <cover_start@plt>
mov    0x2e9a(%rip),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <write@plt>
mov    $0x0,%al
call   1070 <cover_stop@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binfmt>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
cmpl   $0xffffffff,0x2ee7(%rip)
jne    118f <binfmt+0x3f>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1060 <open@plt>
mov    %eax,0x2eca(%rip)
cmp    $0xffffffff,%eax
jne    118f <binfmt+0x3f>
lea    0xe98(%rip),%rdi
call   1040 <fail@plt>
xor    %eax,%eax
call   1050 <cover_start@plt>
mov    0x2eac(%rip),%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <cover_stop@plt>

LLVM IR (-O0):
@binfmt.fd = internal global i32 -1
@.str = [34 x i8] c"/proc/sys/fs/binfmt_misc/register\00"
@O_WRONLY = global i32 0
@.str.1 = [47 x i8] c"open(/proc/sys/fs/binfmt_misc/register) failed\00"
define void @binfmt(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%5 = load i32, i32* @binfmt.fd
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* @binfmt.fd
br label %10
10: ; preds = %7, %2
%11 = load i32, i32* @binfmt.fd
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @fail(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = call i32 (...) @cover_start()
%17 = load i32, i32* @binfmt.fd
%18 = load i8*, i8** %3
%19 = load i64, i64* %4
%20 = call i32 @write(i32 %17, i8* %18, i64 %19)
%21 = call i32 (...) @cover_stop()
ret void
}

LLVM IR (-O2):
@binfmt.fd = internal unnamed_addr global i32 -1
@.str = [34 x i8] c"/proc/sys/fs/binfmt_misc/register\00"
@O_WRONLY = global i32 0
@.str.1 = [47 x i8] c"open(/proc/sys/fs/binfmt_misc/register) failed\00"
define void @binfmt(i8* nocapture %0, i64 %1) {
%3 = load i32, i32* @binfmt.fd
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @O_WRONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* @binfmt.fd
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @fail(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %2, %9, %5
%12 = tail call i32 (...) @cover_start()
%13 = load i32, i32* @binfmt.fd
%14 = tail call i32 @write(i32 %13, i8* %0, i64 %1)
%15 = tail call i32 (...) @cover_stop()
ret void
}