#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*/ clear_memory(int, unsigned int, unsigned int);
int /*<<< orphan*/ fill_memory(int, unsigned int, unsigned char *,
                               unsigned int);
scalar_t__ is_empty(unsigned char *, unsigned int);
int /*<<< orphan*/ print_progress_bar(unsigned int, unsigned int);
int send_file(int serial_fd, unsigned int address, unsigned char *data,
              unsigned int data_length) {
  unsigned int offset = 0;
  print_progress_bar(0, data_length);
  while (offset < data_length) {
    unsigned int this_slice = data_length - offset;
    if (this_slice > 1024)
      this_slice = 1024;
    if (is_empty(data + offset, this_slice)) {
      if (!clear_memory(serial_fd, address + offset, this_slice))
        return 0;
    } else {
      if (!fill_memory(serial_fd, address + offset, data + offset, this_slice))
        return 0;
    }
    offset += this_slice;
    print_progress_bar(offset, data_length);
  }
  return 1;
}


x86 assembly (clang, -O0):
<send_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
xor    %edi,%edi
call   1060 <print_progress_bar@plt>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1224 <send_file+0xe4>
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x400,-0x24(%rbp)
jbe    118f <send_file+0x4f>
movl   $0x400,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%eax
add    %rax,%rdi
mov    -0x24(%rbp),%esi
call   1040 <is_empty@plt>
cmp    $0x0,%rax
je     11d6 <send_file+0x96>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
add    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1050 <clear_memory@plt>
cmp    $0x0,%eax
jne    11d1 <send_file+0x91>
movl   $0x0,-0x4(%rbp)
jmp    122b <send_file+0xeb>
jmp    120b <send_file+0xcb>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
add    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%eax
add    %rax,%rdx
mov    -0x24(%rbp),%ecx
call   1030 <fill_memory@plt>
cmp    $0x0,%eax
jne    1206 <send_file+0xc6>
movl   $0x0,-0x4(%rbp)
jmp    122b <send_file+0xeb>
jmp    120b <send_file+0xcb>
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <print_progress_bar@plt>
jmp    1166 <send_file+0x26>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,(%rsp)
mov    %esi,%r12d
mov    %edi,%r13d
xor    %r15d,%r15d
xor    %edi,%edi
mov    %ecx,%esi
call   1060 <print_progress_bar@plt>
mov    $0x1,%eax
test   %ebx,%ebx
jne    1191 <send_file+0x51>
jmp    11d5 <send_file+0x95>
xchg   %ax,%ax
mov    %r14,%rdx
mov    %ebp,%ecx
call   1030 <fill_memory@plt>
test   %eax,%eax
je     11cc <send_file+0x8c>
add    %r15d,%ebp
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <print_progress_bar@plt>
mov    %ebp,%r15d
cmp    %ebx,%ebp
jae    11d0 <send_file+0x90>
mov    %ebx,%ebp
sub    %r15d,%ebp
cmp    $0x400,%ebp
mov    $0x400,%eax
cmovae %eax,%ebp
mov    %r15d,%r14d
add    (%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <is_empty@plt>
lea    (%r15,%r12,1),%esi
mov    %r13d,%edi
test   %rax,%rax
je     1170 <send_file+0x30>
mov    %ebp,%edx
call   1050 <clear_memory@plt>
test   %eax,%eax
jne    117e <send_file+0x3e>
xor    %eax,%eax
jmp    11d5 <send_file+0x95>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @send_file(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 0, i32* %10
%12 = load i32, i32* %9
%13 = call i32 @print_progress_bar(i32 0, i32 %12)
br label %14
14: ; preds = %57, %4
%15 = load i32, i32* %10
%16 = load i32, i32* %9
%17 = icmp ult i32 %15, %16
br i1 %17, label %18, label %64
18: ; preds = %14
%19 = load i32, i32* %9
%20 = load i32, i32* %10
%21 = sub i32 %19, %20
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = icmp ugt i32 %22, 1024
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 1024, i32* %11
br label %25
25: ; preds = %24, %18
%26 = load i8*, i8** %8
%27 = load i32, i32* %10
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i32, i32* %11
%31 = call i64 @is_empty(i8* %29, i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %25
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = load i32, i32* %10
%37 = add i32 %35, %36
%38 = load i32, i32* %11
%39 = call i32 @clear_memory(i32 %34, i32 %37, i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %33
store i32 0, i32* %5
br label %65
42: ; preds = %33
br label %57
43: ; preds = %25
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = load i32, i32* %10
%47 = add i32 %45, %46
%48 = load i8*, i8** %8
%49 = load i32, i32* %10
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i32, i32* %11
%53 = call i32 @fill_memory(i32 %44, i32 %47, i8* %51, i32 %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %43
store i32 0, i32* %5
br label %65
56: ; preds = %43
br label %57
57: ; preds = %56, %42
%58 = load i32, i32* %11
%59 = load i32, i32* %10
%60 = add i32 %59, %58
store i32 %60, i32* %10
%61 = load i32, i32* %10
%62 = load i32, i32* %9
%63 = call i32 @print_progress_bar(i32 %61, i32 %62)
br label %14
64: ; preds = %14
store i32 1, i32* %5
br label %65
65: ; preds = %64, %55, %41
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
define i32 @send_file(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 @print_progress_bar(i32 0, i32 %3)
%6 = icmp eq i32 %3, 0
br i1 %6, label %27, label %7
7: ; preds = %4, %23
%8 = phi i32 [ %24, %23 ], [ 0, %4 ]
%9 = sub i32 %3, %8
%10 = icmp ult i32 %9, 1024
%11 = select i1 %10, i32 %9, i32 1024
%12 = zext i32 %8 to i64
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = tail call i64 @is_empty(i8* %13, i32 %11)
%15 = icmp eq i64 %14, 0
%16 = add i32 %8, %1
br i1 %15, label %20, label %17
17: ; preds = %7
%18 = tail call i32 @clear_memory(i32 %0, i32 %16, i32 %11)
%19 = icmp eq i32 %18, 0
br i1 %19, label %27, label %23
20: ; preds = %7
%21 = tail call i32 @fill_memory(i32 %0, i32 %16, i8* %13, i32 %11)
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %17, %20
%24 = add i32 %11, %8
%25 = tail call i32 @print_progress_bar(i32 %24, i32 %3)
%26 = icmp ult i32 %24, %3
br i1 %26, label %7, label %27
27: ; preds = %23, %17, %20, %4
%28 = phi i32 [ 1, %4 ], [ 0, %20 ], [ 0, %17 ], [ 1, %23 ]
ret i32 %28
}