#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*/ print_hex(unsigned int);
int /*<<< orphan*/ puts(char *);
unsigned char wait_data();
int ReceiveProgram() {
  unsigned char *ptr = (unsigned char *)0x10000000;
  int y;
  unsigned char data;
  data = wait_data();
  if (data != 0xFF) {
    puts("  + ERROR ON DATA (1)\r\n");
    puts("    - DATA = ");
    print_hex((unsigned int)data);
    puts("\r\n");
  }
  data = wait_data();
  if (data != 0xFF) {
    puts("  + ERROR ON DATA (2)\r\n");
    puts("    - DATA = ");
    print_hex((unsigned int)data);
    puts("\r\n");
  }
  data = wait_data();
  if (data != 0xFF) {
    puts("  + ERROR ON DATA (3)\r\n");
    puts("    - DATA = ");
    print_hex((unsigned int)data);
    puts("\r\n");
  }
  unsigned char data1 = wait_data();
  unsigned char data2 = wait_data();
  unsigned char data3 = wait_data();
  unsigned char data4 = wait_data();
  unsigned int sSize = (data4 << 24) | (data3 << 16) | (data2 << 8) | data1;
  for (y = 0; y < sSize; y++) {
    unsigned char dataS = wait_data();
    ptr[y] = dataS;
  }
  puts("  + DATA RECEPTION COMPLETE\r\n");
  puts("  + # OF OCTETS : ");
  print_hex((unsigned int)sSize);
  puts("\r\n");
  return 1;
}


x86 assembly (clang, -O0):
<ReceiveProgram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x10000000,%eax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <wait_data@plt>
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
cmp    $0xff,%eax
je     1187 <ReceiveProgram+0x57>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
movzbl -0xd(%rbp),%edi
call   1050 <print_hex@plt>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1040 <wait_data@plt>
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
cmp    $0xff,%eax
je     11cd <ReceiveProgram+0x9d>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
movzbl -0xd(%rbp),%edi
call   1050 <print_hex@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1040 <wait_data@plt>
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
cmp    $0xff,%eax
je     1213 <ReceiveProgram+0xe3>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
movzbl -0xd(%rbp),%edi
call   1050 <print_hex@plt>
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1040 <wait_data@plt>
mov    %al,-0xe(%rbp)
mov    $0x0,%al
call   1040 <wait_data@plt>
mov    %al,-0xf(%rbp)
mov    $0x0,%al
call   1040 <wait_data@plt>
mov    %al,-0x10(%rbp)
mov    $0x0,%al
call   1040 <wait_data@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
shl    $0x18,%eax
movzbl -0x10(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movzbl -0xf(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0xe(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1296 <ReceiveProgram+0x166>
mov    $0x0,%al
call   1040 <wait_data@plt>
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1264 <ReceiveProgram+0x134>
lea    0xdb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xdcb(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%edi
call   1050 <print_hex@plt>
lea    0xd58(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReceiveProgram>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <wait_data@plt>
cmp    $0xff,%al
je     116d <ReceiveProgram+0x3d>
movzbl %al,%ebx
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0xec3(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <print_hex@plt>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <wait_data@plt>
cmp    $0xff,%al
je     11a6 <ReceiveProgram+0x76>
movzbl %al,%ebx
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <print_hex@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <wait_data@plt>
cmp    $0xff,%al
je     11df <ReceiveProgram+0xaf>
movzbl %al,%ebx
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1050 <print_hex@plt>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <wait_data@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <wait_data@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1040 <wait_data@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <wait_data@plt>
movzbl %al,%eax
shl    $0x18,%eax
movzbl %bl,%ecx
shl    $0x10,%ecx
or     %eax,%ecx
movzbl %r14b,%eax
shl    $0x8,%eax
or     %ecx,%eax
movzbl %bpl,%r14d
or     %eax,%r14d
je     1246 <ReceiveProgram+0x116>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <wait_data@plt>
mov    %al,0x10000000(%rbx)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1230 <ReceiveProgram+0x100>
lea    0xe09(%rip),%rdi
call   1030 <puts@plt>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1050 <print_hex@plt>
lea    0xda8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c" + ERROR ON DATA (1)\0D\0A\00"
@.str.1 = [14 x i8] c" - DATA = \00"
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [24 x i8] c" + ERROR ON DATA (2)\0D\0A\00"
@.str.4 = [24 x i8] c" + ERROR ON DATA (3)\0D\0A\00"
@.str.5 = [30 x i8] c" + DATA RECEPTION COMPLETE\0D\0A\00"
@.str.6 = [19 x i8] c" + # OF OCTETS : \00"
define i32 @ReceiveProgram() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
%9 = alloca i8
store i8* inttoptr (i64 268435456 to i8*), i8** %1
%10 = call zeroext i8 (...) @wait_data()
store i8 %10, i8* %3
%11 = load i8, i8* %3
%12 = zext i8 %11 to i32
%13 = icmp ne i32 %12, 255
br i1 %13, label %14, label %21
14: ; preds = %0
%15 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
%19 = call i32 @print_hex(i32 %18)
%20 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %14, %0
%22 = call zeroext i8 (...) @wait_data()
store i8 %22, i8* %3
%23 = load i8, i8* %3
%24 = zext i8 %23 to i32
%25 = icmp ne i32 %24, 255
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%29 = load i8, i8* %3
%30 = zext i8 %29 to i32
%31 = call i32 @print_hex(i32 %30)
%32 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %26, %21
%34 = call zeroext i8 (...) @wait_data()
store i8 %34, i8* %3
%35 = load i8, i8* %3
%36 = zext i8 %35 to i32
%37 = icmp ne i32 %36, 255
br i1 %37, label %38, label %45
38: ; preds = %33
%39 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%41 = load i8, i8* %3
%42 = zext i8 %41 to i32
%43 = call i32 @print_hex(i32 %42)
%44 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %38, %33
%46 = call zeroext i8 (...) @wait_data()
store i8 %46, i8* %4
%47 = call zeroext i8 (...) @wait_data()
store i8 %47, i8* %5
%48 = call zeroext i8 (...) @wait_data()
store i8 %48, i8* %6
%49 = call zeroext i8 (...) @wait_data()
store i8 %49, i8* %7
%50 = load i8, i8* %7
%51 = zext i8 %50 to i32
%52 = shl i32 %51, 24
%53 = load i8, i8* %6
%54 = zext i8 %53 to i32
%55 = shl i32 %54, 16
%56 = or i32 %52, %55
%57 = load i8, i8* %5
%58 = zext i8 %57 to i32
%59 = shl i32 %58, 8
%60 = or i32 %56, %59
%61 = load i8, i8* %4
%62 = zext i8 %61 to i32
%63 = or i32 %60, %62
store i32 %63, i32* %8
store i32 0, i32* %2
br label %64
64: ; preds = %75, %45
%65 = load i32, i32* %2
%66 = load i32, i32* %8
%67 = icmp ult i32 %65, %66
br i1 %67, label %68, label %78
68: ; preds = %64
%69 = call zeroext i8 (...) @wait_data()
store i8 %69, i8* %9
%70 = load i8, i8* %9
%71 = load i8*, i8** %1
%72 = load i32, i32* %2
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
store i8 %70, i8* %74
br label %75
75: ; preds = %68
%76 = load i32, i32* %2
%77 = add nsw i32 %76, 1
store i32 %77, i32* %2
br label %64
78: ; preds = %64
%79 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%80 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%81 = load i32, i32* %8
%82 = call i32 @print_hex(i32 %81)
%83 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [24 x i8] c" + ERROR ON DATA (1)\0D\0A\00"
@.str.1 = [14 x i8] c" - DATA = \00"
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [24 x i8] c" + ERROR ON DATA (2)\0D\0A\00"
@.str.4 = [24 x i8] c" + ERROR ON DATA (3)\0D\0A\00"
@.str.5 = [30 x i8] c" + DATA RECEPTION COMPLETE\0D\0A\00"
@.str.6 = [19 x i8] c" + # OF OCTETS : \00"
define i32 @ReceiveProgram() {
%1 = tail call zeroext i8 (...) @wait_data()
%2 = icmp eq i8 %1, -1
br i1 %2, label %9, label %3
3: ; preds = %0
%4 = zext i8 %1 to i32
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @print_hex(i32 %4)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %3, %0
%10 = tail call zeroext i8 (...) @wait_data()
%11 = icmp eq i8 %10, -1
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = zext i8 %10 to i32
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @print_hex(i32 %13)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %12, %9
%19 = tail call zeroext i8 (...) @wait_data()
%20 = icmp eq i8 %19, -1
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = zext i8 %19 to i32
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%25 = tail call i32 @print_hex(i32 %22)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %21, %18
%28 = tail call zeroext i8 (...) @wait_data()
%29 = tail call zeroext i8 (...) @wait_data()
%30 = tail call zeroext i8 (...) @wait_data()
%31 = tail call zeroext i8 (...) @wait_data()
%32 = zext i8 %31 to i32
%33 = shl nuw i32 %32, 24
%34 = zext i8 %30 to i32
%35 = shl nuw nsw i32 %34, 16
%36 = or i32 %33, %35
%37 = zext i8 %29 to i32
%38 = shl nuw nsw i32 %37, 8
%39 = or i32 %36, %38
%40 = zext i8 %28 to i32
%41 = or i32 %39, %40
%42 = icmp eq i32 %41, 0
br i1 %42, label %51, label %43
43: ; preds = %27
%44 = zext i32 %41 to i64
br label %45
45: ; preds = %43, %45
%46 = phi i64 [ 0, %43 ], [ %49, %45 ]
%47 = tail call zeroext i8 (...) @wait_data()
%48 = getelementptr inbounds i8, i8* inttoptr (i64 268435456 to i8*), i64 %46
store i8 %47, i8* %48
%49 = add nuw nsw i64 %46, 1
%50 = icmp eq i64 %49, %44
br i1 %50, label %51, label %45
51: ; preds = %45, %27
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%54 = tail call i32 @print_hex(i32 %41)
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret i32 1
}