#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 */
scalar_t__ malloc(int);
int read(int, unsigned char *, int);
int wma_file_read_bytes(int fd, int len, unsigned char **data) {
  int ret;
  *data = (unsigned char *)malloc(len);
  if (!*data)
    return 0;
  ret = read(fd, *data, len);
  if ((ret < 0) || (ret != len))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<wma_file_read_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    115e <wma_file_read_bytes+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    119c <wma_file_read_bytes+0x7c>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0xc(%rbp),%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1189 <wma_file_read_bytes+0x69>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1195 <wma_file_read_bytes+0x75>
movl   $0x0,-0x4(%rbp)
jmp    119c <wma_file_read_bytes+0x7c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wma_file_read_bytes>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %esi,%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     115a <wma_file_read_bytes+0x3a>
mov    %r14d,%edi
mov    %rax,%rsi
mov    %ebx,%edx
call   1030 <read@plt>
test   %eax,%eax
setns  %cl
cmp    %ebx,%eax
sete   %al
and    %cl,%al
movzbl %al,%eax
jmp    115c <wma_file_read_bytes+0x3c>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @wma_file_read_bytes(i32 %0, i32 %1, i8** nocapture writeonly %2) {
%4 = tail call i64 @malloc(i32 %1)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %2
%6 = icmp eq i64 %4, 0
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = tail call i32 @read(i32 %0, i8* %5, i32 %1)
%9 = icmp sgt i32 %8, -1
%10 = icmp eq i32 %8, %1
%11 = and i1 %9, %10
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %7, %3
%14 = phi i32 [ 0, %3 ], [ %12, %7 ]
ret i32 %14
}