#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 adb_download_buffer(char const *, void *, unsigned int, unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ free(void *);
void *load_file(char const *, unsigned int *);
int /*<<< orphan*/ stderr;
int adb_download(const char *service, const char *fn, unsigned progress) {
  void *data;
  unsigned sz;
  data = load_file(fn, &sz);
  if (data == 0) {
    fprintf(stderr, "* cannot read '%s' *\n", service);
    return -1;
  }
  int status = adb_download_buffer(service, data, sz, progress);
  free(data);
  return status;
}


x86 assembly (clang, -O0):
<adb_download>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <load_file@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1194 <adb_download+0x54>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <adb_download+0x79>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <adb_download_buffer@plt>
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adb_download>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
call   1060 <load_file@plt>
test   %rax,%rax
je     1184 <adb_download+0x44>
mov    %rax,%rbp
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r14d,%ecx
call   1030 <adb_download_buffer@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <free@plt>
jmp    11a1 <adb_download+0x61>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"* cannot read '%s' *\0A\00"
define i32 @adb_download(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %6
%12 = call i8* @load_file(i8* %11, i32* %9)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %4
br label %28
19: ; preds = %3
%20 = load i8*, i8** %5
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = load i32, i32* %7
%24 = call i32 @adb_download_buffer(i8* %20, i8* %21, i32 %22, i32 %23)
store i32 %24, i32* %10
%25 = load i8*, i8** %8
%26 = call i32 @free(i8* %25)
%27 = load i32, i32* %10
store i32 %27, i32* %4
br label %28
28: ; preds = %19, %15
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"* cannot read '%s' *\0A\00"
define i32 @adb_download(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call i8* @load_file(i8* %1, i32* %4)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %15
11: ; preds = %3
%12 = load i32, i32* %4
%13 = call i32 @adb_download_buffer(i8* %0, i8* %6, i32 %12, i32 %2)
%14 = call i32 @free(i8* %6)
br label %15
15: ; preds = %11, %8
%16 = phi i32 [ -1, %8 ], [ %13, %11 ]
ret i32 %16
}