#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 */
float seconds();
scalar_t__ serial_read(char *, int);
int create_read_block(char *data, int count) {
  float start_time;
  int read_count = 0;
  start_time = seconds();
  while (read_count < count && seconds() - start_time < .5)
    read_count += serial_read(data + read_count, count - read_count);
  return read_count;
}


x86 assembly (clang, -O0):
<create_read_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <seconds@plt>
movss  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x15(%rbp)
jge    1175 <create_read_block+0x55>
mov    $0x0,%al
call   1030 <seconds@plt>
subss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe95(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1185 <create_read_block+0x65>
jmp    11ad <create_read_block+0x8d>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
sub    -0x14(%rbp),%esi
call   1040 <serial_read@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    1142 <create_read_block+0x22>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_read_block>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <seconds@plt>
movss  %xmm0,0x4(%rsp)
test   %r15d,%r15d
jle    1185 <create_read_block+0x65>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <seconds@plt>
subss  0x4(%rsp),%xmm0
movss  0xe9b(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1185 <create_read_block+0x65>
movslq %ebx,%rbp
lea    (%r14,%rbp,1),%rdi
mov    %r15d,%esi
sub    %ebp,%esi
call   1040 <serial_read@plt>
mov    %rax,%rbx
add    %ebp,%ebx
cmp    %r15d,%ebx
jl     1150 <create_read_block+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @create_read_block(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca float
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
%7 = call float (...) @seconds()
store float %7, float* %5
br label %8
8: ; preds = %20, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = call float (...) @seconds()
%14 = load float, float* %5
%15 = fsub float %13, %14
%16 = fpext float %15 to double
%17 = fcmp olt double %16, 5.000000e-01
br label %18
18: ; preds = %12, %8
%19 = phi i1 [ false, %8 ], [ %17, %12 ]
br i1 %19, label %20, label %33
20: ; preds = %18
%21 = load i8*, i8** %3
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32, i32* %4
%26 = load i32, i32* %6
%27 = sub nsw i32 %25, %26
%28 = call i64 @serial_read(i8* %24, i32 %27)
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = add nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %6
br label %8
33: ; preds = %18
%34 = load i32, i32* %6
ret i32 %34
}

LLVM IR (-O2):
define i32 @create_read_block(i8* %0, i32 %1) {
%3 = tail call float (...) @seconds()
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %18
5: ; preds = %2, %10
%6 = phi i32 [ %16, %10 ], [ 0, %2 ]
%7 = tail call float (...) @seconds()
%8 = fsub float %7, %3
%9 = fcmp olt float %8, 5.000000e-01
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = sext i32 %6 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = sub nsw i32 %1, %6
%14 = tail call i64 @serial_read(i8* %12, i32 %13)
%15 = trunc i64 %14 to i32
%16 = add i32 %6, %15
%17 = icmp slt i32 %16, %1
br i1 %17, label %5, label %18
18: ; preds = %5, %10, %2
%19 = phi i32 [ 0, %2 ], [ %16, %10 ], [ %6, %5 ]
ret i32 %19
}