#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 */
struct timeval {
  int tv_sec;
  long tv_usec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ timeradd(struct timeval *, struct timeval *,
                            struct timeval *);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
int main() {
  int side1, side2, side3;
  struct timeval timeA;
  struct timeval timeB, timeC, timeD;
  FILE *f1;
  f1 = fopen("triangleData.txt", "r");
  printf("\n\n");
  while (1) {
    fscanf(f1, "%d", &side1);
    fscanf(f1, "%d", &side2);
    fscanf(f1, "%d", &side3);
    if (side1 == 0 || side2 == 0 || side3 == 0) {
      break;
    }
    gettimeofday(&timeA, NULL);
    side1 = side1 * side1;
    side2 = side2 * side2;
    side3 = side3 * side3;
    if (side1 + side2 == side3 || side2 + side3 == side1 ||
        side1 + side3 == side2) {
      gettimeofday(&timeB, NULL);
      printf("right\n");
    } else {
      gettimeofday(&timeB, NULL);
      printf("wrong\n");
    }
    timersub(&timeB, &timeA, &timeC);
    timeradd(&timeC, &timeD, &timeD);
  }
  fclose(f1);
  int tvSec = timeD.tv_sec;
  long tvUSec = timeD.tv_usec;
  printf("sec: %d\tusec: %ld\n\n", tvSec, tvUSec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x58(%rbp)
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%rdi
lea    0xe64(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1070 <fscanf@plt>
mov    -0x58(%rbp),%rdi
lea    0xe50(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1070 <fscanf@plt>
mov    -0x58(%rbp),%rdi
lea    0xe3c(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1070 <fscanf@plt>
cmpl   $0x0,-0x8(%rbp)
je     11fe <main+0x8e>
cmpl   $0x0,-0xc(%rbp)
je     11fe <main+0x8e>
cmpl   $0x0,-0x10(%rbp)
jne    1203 <main+0x93>
jmp    12bc <main+0x14c>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     125b <main+0xeb>
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     125b <main+0xeb>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    127b <main+0x10b>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1296 <main+0x126>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1090 <timersub@plt>
lea    -0x40(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    %rdx,%rsi
call   1040 <timeradd@plt>
jmp    11a4 <main+0x34>
mov    -0x58(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x50(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x5c(%rbp),%esi
mov    -0x68(%rbp),%rdx
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,0x10(%rsp)
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
lea    0xe44(%rip),%rbp
mov    %rbp,%rsi
lea    0xc(%rsp),%rdx
call   1080 <fscanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
lea    0x8(%rsp),%rdx
call   1080 <fscanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
lea    0x4(%rsp),%rdx
call   1080 <fscanf@plt>
cmpl   $0x0,0xc(%rsp)
je     12bf <main+0x13f>
cmpl   $0x0,0x8(%rsp)
je     12bf <main+0x13f>
cmpl   $0x0,0x4(%rsp)
je     12bf <main+0x13f>
lea    0x38(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
mov    0xc(%rsp),%r15d
imul   %r15d,%r15d
mov    %r15d,0xc(%rsp)
mov    0x8(%rsp),%r12d
imul   %r12d,%r12d
mov    %r12d,0x8(%rsp)
mov    0x4(%rsp),%r13d
imul   %r13d,%r13d
mov    %r13d,0x4(%rsp)
lea    (%r12,%r15,1),%r14d
lea    (%r12,%r13,1),%ebp
lea    (%r15,%r13,1),%ebx
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
cmp    %r12d,%ebx
lea    0xdb5(%rip),%rdi
lea    0xdb4(%rip),%rax
cmove  %rax,%rdi
cmp    %r15d,%ebp
cmove  %rax,%rdi
cmp    %r13d,%r14d
cmove  %rax,%rdi
call   1030 <puts@plt>
lea    0x28(%rsp),%rdi
lea    0x38(%rsp),%rsi
lea    0x48(%rsp),%rbx
mov    %rbx,%rdx
call   10a0 <timersub@plt>
mov    %rbx,%rdi
lea    0x18(%rsp),%rdx
mov    %rdx,%rsi
call   1050 <timeradd@plt>
jmp    11c0 <main+0x40>
mov    0x10(%rsp),%rdi
call   1040 <fclose@plt>
mov    0x18(%rsp),%esi
mov    0x20(%rsp),%rdx
lea    0xd3d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [17 x i8] c"triangleData.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [7 x i8] c"right\0A\00"
@.str.5 = [7 x i8] c"wrong\0A\00"
@.str.6 = [20 x i8] c"sec: %d\09usec: %ld\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i64
store i32 0, i32* %1
%12 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %9
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %0, %64
%15 = load i32*, i32** %9
%16 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%17 = load i32*, i32** %9
%18 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%19 = load i32*, i32** %9
%20 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %14
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26, %23, %14
br label %67
30: ; preds = %26
%31 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%32 = load i32, i32* %2
%33 = load i32, i32* %2
%34 = mul nsw i32 %32, %33
store i32 %34, i32* %2
%35 = load i32, i32* %3
%36 = load i32, i32* %3
%37 = mul nsw i32 %35, %36
store i32 %37, i32* %3
%38 = load i32, i32* %4
%39 = load i32, i32* %4
%40 = mul nsw i32 %38, %39
store i32 %40, i32* %4
%41 = load i32, i32* %2
%42 = load i32, i32* %3
%43 = add nsw i32 %41, %42
%44 = load i32, i32* %4
%45 = icmp eq i32 %43, %44
br i1 %45, label %58, label %46
46: ; preds = %30
%47 = load i32, i32* %3
%48 = load i32, i32* %4
%49 = add nsw i32 %47, %48
%50 = load i32, i32* %2
%51 = icmp eq i32 %49, %50
br i1 %51, label %58, label %52
52: ; preds = %46
%53 = load i32, i32* %2
%54 = load i32, i32* %4
%55 = add nsw i32 %53, %54
%56 = load i32, i32* %3
%57 = icmp eq i32 %55, %56
br i1 %57, label %58, label %61
58: ; preds = %52, %46, %30
%59 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %64
61: ; preds = %52
%62 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %64
64: ; preds = %61, %58
%65 = call i32 @timersub(%struct.timeval* %6, %struct.timeval* %5, %struct.timeval* %7)
%66 = call i32 @timeradd(%struct.timeval* %7, %struct.timeval* %8, %struct.timeval* %8)
br label %14
67: ; preds = %29
%68 = load i32*, i32** %9
%69 = call i32 @fclose(i32* %68)
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%71 = load i32, i32* %70
store i32 %71, i32* %10
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%73 = load i64, i64* %72
store i64 %73, i64* %11
%74 = load i32, i32* %10
%75 = load i64, i64* %11
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %74, i64 %75)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [17 x i8] c"triangleData.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.6 = [20 x i8] c"sec: %d\09usec: %ld\0A\0A\00"
@str = [2 x i8] c"\0A\00"
@str.7 = [6 x i8] c"wrong\00"
@str.8 = [6 x i8] c"right\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast %struct.timeval* %4 to i8*
%12 = bitcast %struct.timeval* %5 to i8*
%13 = bitcast %struct.timeval* %6 to i8*
%14 = bitcast %struct.timeval* %7 to i8*
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %29, %0
%18 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%19 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%20 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%21 = load i32, i32* %1
%22 = icmp eq i32 %21, 0
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 0
%25 = select i1 %22, i1 true, i1 %24
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 0
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %50, label %29
29: ; preds = %17
%30 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%31 = load i32, i32* %1
%32 = mul nsw i32 %31, %31
store i32 %32, i32* %1
%33 = load i32, i32* %2
%34 = mul nsw i32 %33, %33
store i32 %34, i32* %2
%35 = load i32, i32* %3
%36 = mul nsw i32 %35, %35
store i32 %36, i32* %3
%37 = add nuw nsw i32 %34, %32
%38 = icmp eq i32 %37, %36
%39 = add nuw nsw i32 %36, %34
%40 = icmp eq i32 %39, %32
%41 = select i1 %38, i1 true, i1 %40
%42 = add nuw nsw i32 %36, %32
%43 = icmp eq i32 %42, %34
%44 = select i1 %41, i1 true, i1 %43
%45 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%46 = select i1 %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.7, i64 0, i64 0)
%47 = call i32 @puts(i8* dereferenceable(1) %46)
%48 = call i32 @timersub(%struct.timeval* %5, %struct.timeval* %4, %struct.timeval* %6)
%49 = call i32 @timeradd(%struct.timeval* %6, %struct.timeval* %7, %struct.timeval* %7)
br label %17
50: ; preds = %17
%51 = call i32 @fclose(i32* %15)
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%55 = load i64, i64* %54
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %53, i64 %55)
ret i32 0
}