#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__ checkch();
int /*<<< orphan*/ getch();
int /*<<< orphan*/ putnum(unsigned int);
int /*<<< orphan*/ putstr(char *);
unsigned int serial_load(void *dst) {
  unsigned char *p = dst;
  unsigned int idle, len;
  putstr("Send binary now...");
  len = 0;
  while (len == 0) {
    for (idle = 0; (idle < 200000); idle++) {
      if (checkch()) {
        *p++ = getch();
        len++;
        idle = 0;
      }
    }
  }
  putstr("\nReceived 0x");
  putnum(len);
  putstr(" bytes\n");
  return len;
}


x86 assembly (clang, -O0):
<serial_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xea5(%rip),%rdi
call   1040 <putstr@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11d8 <serial_load+0x98>
movl   $0x0,-0x14(%rbp)
cmpl   $0x30d40,-0x14(%rbp)
jae    11d3 <serial_load+0x93>
mov    $0x0,%al
call   1030 <checkch@plt>
cmp    $0x0,%rax
je     11c0 <serial_load+0x80>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    11c5 <serial_load+0x85>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1178 <serial_load+0x38>
jmp    1167 <serial_load+0x27>
lea    0xe34(%rip),%rdi
call   1040 <putstr@plt>
mov    -0x18(%rbp),%edi
call   1060 <putnum@plt>
lea    0xe2d(%rip),%rdi
call   1040 <putstr@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_load>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeaf(%rip),%rdi
call   1040 <putstr@plt>
xor    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <checkch@plt>
test   %rax,%rax
je     117f <serial_load+0x3f>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getch@plt>
mov    %al,(%r14)
add    $0x1,%r14
add    $0x1,%ebp
mov    %ebp,%r15d
lea    0x1(%rbx),%eax
cmp    $0x30d3f,%ebx
mov    %eax,%ebx
jb     1160 <serial_load+0x20>
mov    $0x0,%ebp
mov    $0x0,%ebx
test   %r15d,%r15d
je     1160 <serial_load+0x20>
lea    0xe6e(%rip),%rdi
call   1040 <putstr@plt>
mov    %r15d,%edi
call   1060 <putnum@plt>
lea    0xe67(%rip),%rdi
call   1040 <putstr@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Send binary now...\00"
@.str.1 = [13 x i8] c"\0AReceived 0x\00"
@.str.2 = [8 x i8] c" bytes\0A\00"
define i32 @serial_load(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
%7 = call i32 @putstr(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %8
8: ; preds = %29, %1
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %8
store i32 0, i32* %4
br label %12
12: ; preds = %26, %11
%13 = load i32, i32* %4
%14 = icmp ult i32 %13, 200000
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = call i64 (...) @checkch()
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = call i32 (...) @getch()
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
store i8 %20, i8* %21
%23 = load i32, i32* %5
%24 = add i32 %23, 1
store i32 %24, i32* %5
store i32 0, i32* %4
br label %25
25: ; preds = %18, %15
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add i32 %27, 1
store i32 %28, i32* %4
br label %12
29: ; preds = %12
br label %8
30: ; preds = %8
%31 = call i32 @putstr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* %5
%33 = call i32 @putnum(i32 %32)
%34 = call i32 @putstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
@.str = [19 x i8] c"Send binary now...\00"
@.str.1 = [13 x i8] c"\0AReceived 0x\00"
@.str.2 = [8 x i8] c" bytes\0A\00"
define i32 @serial_load(i8* nocapture writeonly %0) {
%2 = tail call i32 @putstr(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %5
3: ; preds = %16
%4 = icmp eq i32 %19, 0
br i1 %4, label %22, label %25
5: ; preds = %22, %1
%6 = phi i32 [ 0, %1 ], [ %23, %22 ]
%7 = phi i32 [ 0, %1 ], [ %24, %22 ]
%8 = phi i8* [ %0, %1 ], [ %17, %22 ]
%9 = tail call i64 (...) @checkch()
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %5
%12 = tail call i32 (...) @getch()
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %13, i8* %8
%15 = add i32 %6, 1
br label %16
16: ; preds = %5, %11
%17 = phi i8* [ %14, %11 ], [ %8, %5 ]
%18 = phi i32 [ 0, %11 ], [ %7, %5 ]
%19 = phi i32 [ %15, %11 ], [ %6, %5 ]
%20 = add nuw nsw i32 %18, 1
%21 = icmp ult i32 %18, 199999
br i1 %21, label %22, label %3
22: ; preds = %16, %3
%23 = phi i32 [ %19, %16 ], [ 0, %3 ]
%24 = phi i32 [ %20, %16 ], [ 0, %3 ]
br label %5
25: ; preds = %3
%26 = tail call i32 @putstr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i32 @putnum(i32 %19)
%28 = tail call i32 @putstr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
ret i32 %19
}