#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int findprop(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int upload(int /*<<< orphan*/ *, int, int);
int pload(char *file, char *port, int type) {
  int rc = 0;
  int count;
  uint8_t dlbuf[0x8000];
  FILE *fp = fopen(file, "rb");
  if (!fp) {
    printf("Can't open '%s' for upload.\n", file);
    return 4;
  } else {
    count = fread(dlbuf, 1, 0x8000, fp);
    printf("Downloading %d bytes of '%s'\n", count, file);
    fclose(fp);
  }
  rc = findprop(port);
  if (!rc && file) {
    rc = upload(dlbuf, count, type);
  }
  return rc;
}


x86 assembly (clang, -O0):
<pload>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20038(%rbp)
cmpq   $0x0,-0x20038(%rbp)
jne    11c0 <pload+0x60>
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x4,-0x4(%rbp)
jmp    123d <pload+0xdd>
lea    -0x20030(%rbp),%rdi
mov    -0x20038(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8000,%edx
call   1040 <fread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20038(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1070 <findprop@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1237 <pload+0xd7>
cmpq   $0x0,-0x10(%rbp)
je     1237 <pload+0xd7>
lea    -0x20030(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1030 <upload@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pload>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20000,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe81(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e0 <pload+0x80>
mov    %rax,%rbp
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x8000,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %eax,%r12d
lea    0xe75(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1070 <findprop@plt>
test   %rbx,%rbx
je     11f6 <pload+0x96>
test   %eax,%eax
jne    11f6 <pload+0x96>
mov    %rsp,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
call   1030 <upload@plt>
jmp    11f6 <pload+0x96>
lea    0xe1c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x4,%eax
add    $0x20000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [29 x i8] c"Can't open '%s' for upload.\0A\00"
@.str.2 = [30 x i8] c"Downloading %d bytes of '%s'\0A\00"
define i32 @pload(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [32768 x i32]
%11 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %11
%14 = load i32*, i32** %11
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %17)
store i32 4, i32* %4
br label %43
19: ; preds = %3
%20 = getelementptr inbounds [32768 x i32], [32768 x i32]* %10, i64 0, i64 0
%21 = load i32*, i32** %11
%22 = call i32 @fread(i32* %20, i32 1, i32 32768, i32* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = load i8*, i8** %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %24)
%26 = load i32*, i32** %11
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %19
%29 = load i8*, i8** %6
%30 = call i32 @findprop(i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp ne i32 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %28
%34 = load i8*, i8** %5
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = getelementptr inbounds [32768 x i32], [32768 x i32]* %10, i64 0, i64 0
%38 = load i32, i32* %9
%39 = load i32, i32* %7
%40 = call i32 @upload(i32* %37, i32 %38, i32 %39)
store i32 %40, i32* %8
br label %41
41: ; preds = %36, %33, %28
%42 = load i32, i32* %8
store i32 %42, i32* %4
br label %43
43: ; preds = %41, %16
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [29 x i8] c"Can't open '%s' for upload.\0A\00"
@.str.2 = [30 x i8] c"Downloading %d bytes of '%s'\0A\00"
define i32 @pload(i8* %0, i8* %1, i32 %2) {
%4 = alloca [32768 x i32]
%5 = bitcast [32768 x i32]* %4 to i8*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %21
10: ; preds = %3
%11 = getelementptr inbounds [32768 x i32], [32768 x i32]* %4, i64 0, i64 0
%12 = call i32 @fread(i32* %11, i32 1, i32 32768, i32* %6)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %0)
%14 = tail call i32 @fclose(i32* %6)
%15 = tail call i32 @findprop(i8* %1)
%16 = icmp eq i32 %15, 0
%17 = icmp ne i8* %0, null
%18 = and i1 %17, %16
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @upload(i32* %11, i32 %12, i32 %2)
br label %21
21: ; preds = %10, %19, %8
%22 = phi i32 [ 4, %8 ], [ %20, %19 ], [ %15, %10 ]
ret i32 %22
}