#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 */
unsigned int get_socket();
int /*<<< orphan*/ ready_socket();
unsigned application_get_data(unsigned packet[], unsigned start) {
  unsigned i, index, length;
  if (!ready_socket()) {
    return 0;
  }
  index = start;
  length = get_socket();
  for (i = 0; i < length; i += 2) {
    packet[index] = get_socket();
    index++;
  }
  return length;
}


x86 assembly (clang, -O0):
<application_get_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1040 <ready_socket@plt>
cmp    $0x0,%eax
jne    114b <application_get_data+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    119e <application_get_data+0x7e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <get_socket@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    1198 <application_get_data+0x78>
mov    $0x0,%al
call   1030 <get_socket@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <application_get_data+0x42>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<application_get_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <ready_socket@plt>
test   %eax,%eax
je     116b <application_get_data+0x4b>
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <get_socket@plt>
test   %eax,%eax
je     116b <application_get_data+0x4b>
mov    %eax,%r12d
xor    %ebp,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <get_socket@plt>
mov    %ebx,%ecx
mov    %eax,(%r14,%rcx,4)
add    $0x1,%ebx
add    $0x2,%ebp
cmp    %r12d,%ebp
jb     1150 <application_get_data+0x30>
mov    %r12d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @application_get_data(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%9 = call i32 (...) @ready_socket()
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %32
12: ; preds = %2
%13 = load i32, i32* %5
store i32 %13, i32* %7
%14 = call i32 (...) @get_socket()
store i32 %14, i32* %8
store i32 0, i32* %6
br label %15
15: ; preds = %27, %12
%16 = load i32, i32* %6
%17 = load i32, i32* %8
%18 = icmp ult i32 %16, %17
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = call i32 (...) @get_socket()
%21 = load i32*, i32** %4
%22 = load i32, i32* %7
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
store i32 %20, i32* %24
%25 = load i32, i32* %7
%26 = add i32 %25, 1
store i32 %26, i32* %7
br label %27
27: ; preds = %19
%28 = load i32, i32* %6
%29 = add i32 %28, 2
store i32 %29, i32* %6
br label %15
30: ; preds = %15
%31 = load i32, i32* %8
store i32 %31, i32* %3
br label %32
32: ; preds = %30, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @application_get_data(i32* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 (...) @ready_socket()
%4 = icmp eq i32 %3, 0
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = tail call i32 (...) @get_socket()
%7 = icmp eq i32 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %5, %8
%9 = phi i32 [ %14, %8 ], [ %1, %5 ]
%10 = phi i32 [ %15, %8 ], [ 0, %5 ]
%11 = tail call i32 (...) @get_socket()
%12 = zext i32 %9 to i64
%13 = getelementptr inbounds i32, i32* %0, i64 %12
store i32 %11, i32* %13
%14 = add i32 %9, 1
%15 = add i32 %10, 2
%16 = icmp ult i32 %15, %6
br i1 %16, label %8, label %17
17: ; preds = %8, %5, %2
%18 = phi i32 [ 0, %2 ], [ 0, %5 ], [ %6, %8 ]
ret i32 %18
}