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


x86 assembly (clang, -O0):
<read_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 <read_binary+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    1194 <read_binary+0x84>
cmpq   $0x0,-0x10(%rbp)
je     115f <read_binary+0x4f>
cmpq   $0x0,-0x18(%rbp)
je     115f <read_binary+0x4f>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    116b <read_binary+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    1194 <read_binary+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rcx
mov    -0x18(%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):
<read_binary>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%eax
test   %rdx,%rdx
je     1145 <read_binary+0x35>
xor    %eax,%eax
test   %rdi,%rdi
je     1145 <read_binary+0x35>
mov    %rsi,%r14
test   %rsi,%rsi
je     1145 <read_binary+0x35>
mov    (%r14),%rsi
test   %rsi,%rsi
je     1145 <read_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 @read_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*** %6
%16 = icmp ne i8** %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i8**, i8*** %6
%19 = load i8*, i8** %18
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %17, %14, %11
store i32 0, i32* %4
br label %32
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i8**, i8*** %6
%25 = load i8*, i8** %24
%26 = load i64, i64* %7
%27 = call i32 @memcpy(i8* %23, i8* %25, i64 %26)
%28 = load i64, i64* %7
%29 = load i8**, i8*** %6
%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 @read_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 ne i8* %0, null
%7 = icmp ne i8** %1, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = load i8*, i8** %1
%11 = icmp eq i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = tail call i32 @memcpy(i8* %0, i8* %10, i64 %2)
%14 = load i8*, i8** %1
%15 = getelementptr inbounds i8, i8* %14, i64 %2
store i8* %15, i8** %1
br label %16
16: ; preds = %5, %9, %3, %12
%17 = phi i32 [ 1, %12 ], [ 1, %3 ], [ 0, %9 ], [ 0, %5 ]
ret i32 %17
}