#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*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, double *, double *, double *);
int /*<<< orphan*/ stderr;
int read_frame(FILE *in, int num_of_coord, float coord[]) {
  int i;
  double d[3];
  char line[1024];
  for (i = 0; i < num_of_coord; i++) {
    if (fgets(line, 1024 - 1, in) == NULL) {
      if (i == 0)
        return -1;
      fprintf(stderr, "incomplete coordinate frame during read %d", i);
      exit(1);
    }
    sscanf(line, " %lf %lf %lf", &d[0], &d[1], &d[2]);
    *coord++ = (float)d[0];
    *coord++ = (float)d[1];
    *coord++ = (float)d[2];
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_frame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1249 <read_frame+0x109>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3ff,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
jne    11c0 <read_frame+0x80>
cmpl   $0x0,-0x24(%rbp)
jne    119e <read_frame+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1250 <read_frame+0x110>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    -0x440(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x40(%rbp),%rcx
add    $0x8,%rcx
lea    -0x40(%rbp),%r8
add    $0x10,%r8
lea    0xe49(%rip),%rsi
call   1050 <sscanf@plt>
movsd  -0x40(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
movss  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
movss  %xmm0,(%rax)
movsd  -0x30(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
movss  %xmm0,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115d <read_frame+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_frame>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
test   %esi,%esi
jle    11d8 <read_frame+0x98>
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebp,%ebp
lea    0x20(%rsp),%r12
mov    %rsp,%r13
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x3ff,%esi
mov    %r15,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11dc <read_frame+0x9c>
mov    %r12,%rdi
lea    0xe9c(%rip),%rsi
mov    %r13,%rdx
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
call   1050 <sscanf@plt>
movsd  (%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,(%rbx)
movsd  0x8(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x4(%rbx)
movsd  0x10(%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rbx)
add    $0x1,%ebp
add    $0xc,%rbx
cmp    %ebp,%r14d
jne    1170 <read_frame+0x30>
xor    %eax,%eax
jmp    11e5 <read_frame+0xa5>
mov    $0xffffffff,%eax
test   %ebp,%ebp
jne    11f7 <read_frame+0xb7>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
mov    %ebp,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"incomplete coordinate frame during read %d\00"
@.str.1 = [13 x i8] c" %lf %lf %lf\00"
define i32 @read_frame(i32* %0, i32 %1, float* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca float*
%8 = alloca i32
%9 = alloca [3 x double]
%10 = alloca [1024 x i8]
store i32* %0, i32** %5
store i32 %1, i32* %6
store float* %2, float** %7
store i32 0, i32* %8
br label %11
11: ; preds = %50, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %53
15: ; preds = %11
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%17 = load i32*, i32** %5
%18 = call i32* @fgets(i8* %16, i32 1023, i32* %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 -1, i32* %4
br label %54
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i32, i32* %8
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %15
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%31 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%32 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
%33 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
%34 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double* %31, double* %32, double* %33)
%35 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 0
%36 = load double, double* %35
%37 = fptrunc double %36 to float
%38 = load float*, float** %7
%39 = getelementptr inbounds float, float* %38, i32 1
store float* %39, float** %7
store float %37, float* %38
%40 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 1
%41 = load double, double* %40
%42 = fptrunc double %41 to float
%43 = load float*, float** %7
%44 = getelementptr inbounds float, float* %43, i32 1
store float* %44, float** %7
store float %42, float* %43
%45 = getelementptr inbounds [3 x double], [3 x double]* %9, i64 0, i64 2
%46 = load double, double* %45
%47 = fptrunc double %46 to float
%48 = load float*, float** %7
%49 = getelementptr inbounds float, float* %48, i32 1
store float* %49, float** %7
store float %47, float* %48
br label %50
50: ; preds = %29
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %11
53: ; preds = %11
store i32 0, i32* %4
br label %54
54: ; preds = %53, %23
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"incomplete coordinate frame during read %d\00"
@.str.1 = [13 x i8] c" %lf %lf %lf\00"
define i32 @read_frame(i32* nocapture %0, i32 %1, float* nocapture writeonly %2) {
%4 = alloca [3 x double]
%5 = alloca [1024 x i8]
%6 = bitcast [3 x double]* %4 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %37
9: ; preds = %3
%10 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 0
%11 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 1
%12 = getelementptr inbounds [3 x double], [3 x double]* %4, i64 0, i64 2
br label %13
13: ; preds = %9, %24
%14 = phi i32 [ 0, %9 ], [ %35, %24 ]
%15 = phi float* [ %2, %9 ], [ %34, %24 ]
%16 = call i32* @fgets(i8* %7, i32 1023, i32* %0)
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = icmp eq i32 %14, 0
br i1 %19, label %37, label %20
20: ; preds = %18
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %14)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %13
%25 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), double* %10, double* %11, double* %12)
%26 = load double, double* %10
%27 = fptrunc double %26 to float
%28 = getelementptr inbounds float, float* %15, i64 1
store float %27, float* %15
%29 = load double, double* %11
%30 = fptrunc double %29 to float
%31 = getelementptr inbounds float, float* %15, i64 2
store float %30, float* %28
%32 = load double, double* %12
%33 = fptrunc double %32 to float
%34 = getelementptr inbounds float, float* %15, i64 3
store float %33, float* %31
%35 = add nuw nsw i32 %14, 1
%36 = icmp eq i32 %35, %1
br i1 %36, label %37, label %13
37: ; preds = %24, %3, %18
%38 = phi i32 [ -1, %18 ], [ 0, %3 ], [ 0, %24 ]
ret i32 %38
}