#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 BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, float *, float *);
int /*<<< orphan*/ system(char *);
int main() {
  FILE *fp;
  FILE *collision;
  char buff[BUFSIZ];
  float absvalue(float);
  int i, j;
  float angle, moment, angle2, moment2;
  angle2 = 90;
  moment2 = 1;
  i = 0;
  while (i == 0) {
    system("bash ./utilities/test_script");
    fp = fopen("./forceBalance.dat", "r");
    if (fp != NULL) {
      while (fgets(buff, sizeof buff, fp) != NULL) {
        sscanf(buff, "%f %f", &angle, &moment);
      }
      if (absvalue(angle - angle2) < 5e-4) {
        i = 1;
      }
      if ((absvalue(angle - angle2) < 1e-3) && (moment2 * moment > 0) &&
          (absvalue(moment2 - moment) < 1e-4)) {
        i = 1;
      }
      angle2 = angle;
      moment2 = moment;
    } else {
      printf("Error!! forcebalance.dat not found!\n");
      return 1;
    }
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movss  0xe4d(%rip),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  0xe3c(%rip),%xmm0
movss  %xmm0,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1320 <main+0x1b0>
lea    0xe3f(%rip),%rdi
call   1050 <system@plt>
lea    0xe50(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12f3 <main+0x183>
jmp    120d <main+0x9d>
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1247 <main+0xd7>
mov    -0x50(%rbp),%rdi
lea    0xe1d(%rip),%rsi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1080 <sscanf@plt>
jmp    120d <main+0x9d>
movss  -0x34(%rbp),%xmm0
subss  -0x3c(%rbp),%xmm0
call   1030 <absvalue@plt>
cvtss2sd %xmm0,%xmm1
movsd  0xda6(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1273 <main+0x103>
movl   $0x1,-0x2c(%rbp)
movss  -0x34(%rbp),%xmm0
subss  -0x3c(%rbp),%xmm0
call   1030 <absvalue@plt>
cvtss2sd %xmm0,%xmm1
movsd  0xd82(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12da <main+0x16a>
movss  -0x40(%rbp),%xmm0
mulss  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jbe    12da <main+0x16a>
movss  -0x40(%rbp),%xmm0
subss  -0x38(%rbp),%xmm0
call   1030 <absvalue@plt>
cvtss2sd %xmm0,%xmm1
movsd  0xd4f(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12da <main+0x16a>
movl   $0x1,-0x2c(%rbp)
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
jmp    1312 <main+0x1a2>
lea    0xd5e(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    1327 <main+0x1b7>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    11d0 <main+0x60>
movl   $0x0,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e58(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movss  0xe59(%rip),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  0xe50(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
lea    -0x34(%rbp),%r13
lea    -0x38(%rbp),%r14
jmp    120d <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movss  -0x40(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x38(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    %r12,%rdi
call   1050 <fclose@plt>
movsd  0xe1e(%rip),%xmm0
ucomisd -0x40(%rbp),%xmm0
ja     1309 <main+0x199>
lea    0xe14(%rip),%rdi
call   1060 <system@plt>
lea    0xe25(%rip),%rdi
lea    0xe31(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     130d <main+0x19d>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %rax,%rdx
mov    %rax,-0x48(%rbp)
call   1070 <fgets@plt>
test   %rax,%rax
lea    0xe09(%rip),%r12
je     1285 <main+0x115>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
call   1080 <sscanf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    -0x48(%rbp),%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1260 <main+0xf0>
mov    -0x48(%rbp),%r12
movss  -0x34(%rbp),%xmm0
subss  -0x30(%rbp),%xmm0
call   1040 <absvalue@plt>
movss  %xmm0,-0x40(%rbp)
movss  -0x34(%rbp),%xmm0
subss  -0x30(%rbp),%xmm0
call   1040 <absvalue@plt>
cvtss2sd %xmm0,%xmm0
movsd  0xd58(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11d0 <main+0x60>
movss  -0x38(%rbp),%xmm2
movss  -0x2c(%rbp),%xmm1
mulss  %xmm2,%xmm1
ucomiss 0xd31(%rip),%xmm1
jbe    11d0 <main+0x60>
movss  -0x2c(%rbp),%xmm0
subss  %xmm2,%xmm0
call   1040 <absvalue@plt>
cvtss2sd %xmm0,%xmm0
movsd  0xd21(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11d0 <main+0x60>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
jmp    131e <main+0x1ae>
lea    0xd4c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [29 x i8] c"bash ./utilities/test_script\00"
@.str.1 = [19 x i8] c"./forceBalance.dat\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%f %f\00"
@.str.4 = [37 x i8] c"Error!! forcebalance.dat not found!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca i32
store i32 0, i32* %1
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %4
%16 = alloca i8, i64 %14
store i64 %14, i64* %5
store float 9.000000e+01, float* %10
store float 1.000000e+00, float* %11
store i32 0, i32* %6
br label %17
17: ; preds = %66, %0
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %69
20: ; preds = %17
%21 = call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%22 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %2
%23 = load i32*, i32** %2
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %64
25: ; preds = %20
br label %26
26: ; preds = %31, %25
%27 = trunc i64 %14 to i32
%28 = load i32*, i32** %2
%29 = call i32* @fgets(i8* %16, i32 %27, i32* %28)
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), float* %8, float* %9)
br label %26
33: ; preds = %26
%34 = load float, float* %8
%35 = load float, float* %10
%36 = fsub float %34, %35
%37 = call float @absvalue(float %36)
%38 = fpext float %37 to double
%39 = fcmp olt double %38, 5.000000e-04
br i1 %39, label %40, label %41
40: ; preds = %33
store i32 1, i32* %6
br label %41
41: ; preds = %40, %33
%42 = load float, float* %8
%43 = load float, float* %10
%44 = fsub float %42, %43
%45 = call float @absvalue(float %44)
%46 = fpext float %45 to double
%47 = fcmp olt double %46, 1.000000e-03
br i1 %47, label %48, label %61
48: ; preds = %41
%49 = load float, float* %11
%50 = load float, float* %9
%51 = fmul float %49, %50
%52 = fcmp ogt float %51, 0.000000e+00
br i1 %52, label %53, label %61
53: ; preds = %48
%54 = load float, float* %11
%55 = load float, float* %9
%56 = fsub float %54, %55
%57 = call float @absvalue(float %56)
%58 = fpext float %57 to double
%59 = fcmp olt double %58, 1.000000e-04
br i1 %59, label %60, label %61
60: ; preds = %53
store i32 1, i32* %6
br label %61
61: ; preds = %60, %53, %48, %41
%62 = load float, float* %8
store float %62, float* %10
%63 = load float, float* %9
store float %63, float* %11
br label %66
64: ; preds = %20
%65 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %12
br label %70
66: ; preds = %61
%67 = load i32*, i32** %2
%68 = call i32 @fclose(i32* %67)
br label %17
69: ; preds = %17
store i32 0, i32* %12
br label %70
70: ; preds = %69, %64
%71 = load i8*, i8** %4
%72 = load i32, i32* %12
switch i32 %72, label %75 [
i32 0, label %73
i32 1, label %73
]
73: ; preds = %70, %70
%74 = load i32, i32* %1
ret i32 %74
75: ; preds = %70
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [29 x i8] c"bash ./utilities/test_script\00"
@.str.1 = [19 x i8] c"./forceBalance.dat\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [6 x i8] c"%f %f\00"
@str = [36 x i8] c"Error!! forcebalance.dat not found!\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast float* %1 to i8*
%7 = bitcast float* %2 to i8*
br label %8
8: ; preds = %0, %43
%9 = phi float [ 1.000000e+00, %0 ], [ %45, %43 ]
%10 = phi float [ 9.000000e+01, %0 ], [ %44, %43 ]
%11 = call i32 @system(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%12 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %47, label %14
14: ; preds = %8
%15 = call i32* @fgets(i8* %5, i32 %3, i32* %12)
%16 = icmp eq i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %14, %17
%18 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), float* %1, float* %2)
%19 = call i32* @fgets(i8* %5, i32 %3, i32* %12)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %17
21: ; preds = %17, %14
%22 = load float, float* %1
%23 = fsub float %22, %10
%24 = call float @absvalue(float %23)
%25 = fpext float %24 to double
%26 = fcmp olt double %25, 5.000000e-04
%27 = load float, float* %1
%28 = fsub float %27, %10
%29 = call float @absvalue(float %28)
%30 = fpext float %29 to double
%31 = fcmp olt double %30, 1.000000e-03
br i1 %31, label %32, label %43
32: ; preds = %21
%33 = load float, float* %2
%34 = fmul float %9, %33
%35 = fcmp ogt float %34, 0.000000e+00
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = fsub float %9, %33
%38 = call float @absvalue(float %37)
%39 = fpext float %38 to double
%40 = fcmp olt double %39, 1.000000e-04
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @fclose(i32* %12)
br label %49
43: ; preds = %36, %32, %21
%44 = load float, float* %1
%45 = load float, float* %2
%46 = call i32 @fclose(i32* %12)
br i1 %26, label %49, label %8
47: ; preds = %8
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %49
49: ; preds = %43, %41, %47
%50 = phi i32 [ 1, %47 ], [ 0, %41 ], [ 0, %43 ]
ret i32 %50
}