#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*/ memcpy(unsigned char *, unsigned char const *, size_t);
int write_binary(unsigned char **dest, const unsigned char *src,
                 size_t amount) {
  if (amount == 0)
    return 1;
  if (!dest || !*dest || !src)
    return 0;
  memcpy(*dest, src, amount);
  *dest += amount;
  return 1;
}


x86 assembly (clang, -O0):
<write_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    113b <write_binary+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    1194 <write_binary+0x84>
cmpq   $0x0,-0x10(%rbp)
je     115f <write_binary+0x4f>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     115f <write_binary+0x4f>
cmpq   $0x0,-0x18(%rbp)
jne    116b <write_binary+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    1194 <write_binary+0x84>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_binary>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%eax
test   %rdx,%rdx
je     1145 <write_binary+0x35>
mov    %rdi,%r14
xor    %eax,%eax
test   %rdi,%rdi
je     1145 <write_binary+0x35>
test   %rsi,%rsi
je     1145 <write_binary+0x35>
mov    (%r14),%rdi
test   %rdi,%rdi
je     1145 <write_binary+0x35>
mov    %rdx,%rbx
call   1030 <memcpy@plt>
add    %rbx,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @write_binary(i8** %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%8 = load i64, i64* %7
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 1, i32* %4
br label %32
11: ; preds = %3
%12 = load i8**, i8*** %5
%13 = icmp ne i8** %12, null
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %18, %14, %11
store i32 0, i32* %4
br label %32
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i8*, i8** %23
%25 = load i8*, i8** %6
%26 = load i64, i64* %7
%27 = call i32 @memcpy(i8* %24, i8* %25, i64 %26)
%28 = load i64, i64* %7
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8, i8* %30, i64 %28
store i8* %31, i8** %29
store i32 1, i32* %4
br label %32
32: ; preds = %22, %21, %10
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @write_binary(i8** %0, i8* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = icmp eq i8** %0, null
br i1 %6, label %16, label %7
7: ; preds = %5
%8 = load i8*, i8** %0
%9 = icmp ne i8* %8, null
%10 = icmp ne i8* %1, null
%11 = and i1 %10, %9
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = tail call i32 @memcpy(i8* %8, i8* %1, i64 %2)
%14 = load i8*, i8** %0
%15 = getelementptr inbounds i8, i8* %14, i64 %2
store i8* %15, i8** %0
br label %16
16: ; preds = %5, %7, %3, %12
%17 = phi i32 [ 1, %12 ], [ 1, %3 ], [ 0, %7 ], [ 0, %5 ]
ret i32 %17
}