#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(float *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
float strtof(char *, char **);
int strtol(char *, char **, int /*<<< orphan*/);
int get_times(FILE *fd, int lanes, float *results, int debug) {
  char time_data[80];
  int i;
  int retval = 0;
  char *next = time_data;
  int lane;
  float current;
  if (!fgets(time_data, 80, fd)) {
    fprintf(stderr,
            "Eek! Error reading from serial port! Please check timer.\n");
    return -1;
  }
  memset(results, 0, sizeof(float) * lanes);
  for (i = 0; i < lanes; i++) {
    lane = strtol(next, &next, 0);
    if (i == 0)
      retval = lane;
    current = strtof(next, &next);
    if (current == 0.0)
      break;
    results[lane - 1] = current;
  }
  return retval;
}


x86 assembly (clang, -O0):
<get_times>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0x0,-0x88(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11ba <get_times+0x6a>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <get_times+0x145>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    128c <get_times+0x13c>
mov    -0x90(%rbp),%rdi
lea    -0x90(%rbp),%rsi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x84(%rbp)
jne    121c <get_times+0xcc>
mov    -0x94(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    -0x90(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1030 <strtof@plt>
movss  %xmm0,-0x98(%rbp)
ff
movss  -0x98(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    125b <get_times+0x10b>
jp     125b <get_times+0x10b>
jmp    128c <get_times+0x13c>
movss  -0x98(%rbp),%xmm0
ff
mov    -0x20(%rbp),%rax
mov    -0x94(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11d9 <get_times+0x89>
mov    -0x88(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_times>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%rdx
lea    0x10(%rsp),%rdi
mov    %rdi,0x8(%rsp)
mov    $0x50,%esi
call   1050 <fgets@plt>
test   %eax,%eax
je     1219 <get_times+0xc9>
lea    0x0(,%rbx,4),%edx
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
test   %ebx,%ebx
jle    1234 <get_times+0xe4>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rbp
mov    %rbp,%rsi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,%r15d
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
call   1030 <strtof@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11ca <get_times+0x7a>
jnp    1234 <get_times+0xe4>
lea    0x8(%rsp),%r12
mov    %r15d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ebp,%rax
movss  %xmm0,-0x4(%r14,%rax,4)
add    $0xffffffff,%ebx
je     1234 <get_times+0xe4>
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
call   1030 <strtof@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11e0 <get_times+0x90>
jp     11e0 <get_times+0x90>
jmp    1234 <get_times+0xe4>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [58 x i8] c"Eek! Error reading from serial port! Please check timer.\0A\00"
define i32 @get_times(i32* %0, i32 %1, float* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca float*
%9 = alloca i32
%10 = alloca [80 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca float
store i32* %0, i32** %6
store i32 %1, i32* %7
store float* %2, float** %8
store i32 %3, i32* %9
store i32 0, i32* %12
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
store i8* %16, i8** %13
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%18 = load i32*, i32** %6
%19 = call i32 @fgets(i8* %17, i32 80, i32* %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %4
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %61
24: ; preds = %4
%25 = load float*, float** %8
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = mul i64 4, %27
%29 = trunc i64 %28 to i32
%30 = call i32 @memset(float* %25, i32 0, i32 %29)
store i32 0, i32* %11
br label %31
31: ; preds = %56, %24
%32 = load i32, i32* %11
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %59
35: ; preds = %31
%36 = load i8*, i8** %13
%37 = call i32 @strtol(i8* %36, i8** %13, i32 0)
store i32 %37, i32* %14
%38 = load i32, i32* %11
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = load i32, i32* %14
store i32 %41, i32* %12
br label %42
42: ; preds = %40, %35
%43 = load i8*, i8** %13
%44 = call float @strtof(i8* %43, i8** %13)
store float %44, float* %15
%45 = load float, float* %15
%46 = fpext float %45 to double
%47 = fcmp oeq double %46, 0.000000e+00
br i1 %47, label %48, label %49
48: ; preds = %42
br label %59
49: ; preds = %42
%50 = load float, float* %15
%51 = load float*, float** %8
%52 = load i32, i32* %14
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds float, float* %51, i64 %54
store float %50, float* %55
br label %56
56: ; preds = %49
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %31
59: ; preds = %48, %31
%60 = load i32, i32* %12
store i32 %60, i32* %5
br label %61
61: ; preds = %59, %21
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [58 x i8] c"Eek! Error reading from serial port! Please check timer.\0A\00"
define i32 @get_times(i32* nocapture %0, i32 %1, float* %2, i32 %3) {
%5 = alloca [80 x i8]
%6 = alloca i8*
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%8 = bitcast i8** %6 to i8*
store i8* %7, i8** %6
%9 = call i32 @fgets(i8* %7, i32 80, i32* %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
br label %38
14: ; preds = %4
%15 = shl i32 %1, 2
%16 = call i32 @memset(float* %2, i32 0, i32 %15)
%17 = icmp sgt i32 %1, 0
br i1 %17, label %18, label %38
18: ; preds = %14
%19 = call i32 @strtol(i8* %7, i8** %6, i32 0)
%20 = load i8*, i8** %6
%21 = call float @strtof(i8* %20, i8** %6)
%22 = fcmp oeq float %21, 0.000000e+00
br i1 %22, label %38, label %23
23: ; preds = %18, %32
%24 = phi float [ %36, %32 ], [ %21, %18 ]
%25 = phi i32 [ %34, %32 ], [ %19, %18 ]
%26 = phi i32 [ %30, %32 ], [ 0, %18 ]
%27 = add nsw i32 %25, -1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds float, float* %2, i64 %28
store float %24, float* %29
%30 = add nuw nsw i32 %26, 1
%31 = icmp eq i32 %30, %1
br i1 %31, label %38, label %32
32: ; preds = %23
%33 = load i8*, i8** %6
%34 = call i32 @strtol(i8* %33, i8** %6, i32 0)
%35 = load i8*, i8** %6
%36 = call float @strtof(i8* %35, i8** %6)
%37 = fcmp oeq float %36, 0.000000e+00
br i1 %37, label %38, label %23
38: ; preds = %23, %32, %18, %14, %11
%39 = phi i32 [ -1, %11 ], [ 0, %14 ], [ %19, %18 ], [ %19, %32 ], [ %19, %23 ]
ret i32 %39
}