#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 timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
unsigned long delta_t(struct timespec *, struct timespec *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
unsigned long compute_delta() {
  struct timespec t1, t2, t3, t4;
  unsigned long d1, d2, d3;
  if (clock_gettime(CLOCK_MONOTONIC, &t1) < 0) {
    perror("clock_gettime");
    exit(-1);
  }
  if (clock_gettime(CLOCK_MONOTONIC, &t2) < 0) {
    perror("clock_gettime");
    exit(-1);
  }
  if (clock_gettime(CLOCK_MONOTONIC, &t3) < 0) {
    perror("clock_gettime");
    exit(-1);
  }
  if (clock_gettime(CLOCK_MONOTONIC, &t4) < 0) {
    perror("clock_gettime");
    exit(-1);
  }
  d1 = delta_t(&t1, &t2);
  d2 = delta_t(&t2, &t3);
  d3 = delta_t(&t3, &t4);
  if (d1 <= d2) {
    if (d2 <= d3)
      return d2;
    else if (d1 <= d3)
      return d3;
    else
      return d1;
  } else {
    if (d1 <= d3)
      return d1;
    else if (d2 <= d3)
      return d3;
    else
      return d2;
  }
}


x86 assembly (clang, -O0):
<compute_delta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
jge    117a <compute_delta+0x3a>
lea    0xe95(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
jge    11ac <compute_delta+0x6c>
lea    0xe63(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
jge    11de <compute_delta+0x9e>
lea    0xe31(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
jge    1210 <compute_delta+0xd0>
lea    0xdff(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <delta_t@plt>
mov    %rax,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <delta_t@plt>
mov    %rax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <delta_t@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
ja     1294 <compute_delta+0x154>
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
ja     126c <compute_delta+0x12c>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <compute_delta+0x192>
mov    -0x30(%rbp),%rax
cmp    -0x40(%rbp),%rax
ja     1287 <compute_delta+0x147>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <compute_delta+0x192>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <compute_delta+0x192>
mov    -0x30(%rbp),%rax
cmp    -0x40(%rbp),%rax
ja     12af <compute_delta+0x16f>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <compute_delta+0x192>
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
ja     12ca <compute_delta+0x18a>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12d2 <compute_delta+0x192>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_delta>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e98(%rip),%rbx
mov    (%rbx),%edi
lea    0x18(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
js     1202 <compute_delta+0xc2>
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
js     1202 <compute_delta+0xc2>
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
js     1202 <compute_delta+0xc2>
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
js     1202 <compute_delta+0xc2>
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1030 <delta_t@plt>
mov    %rax,%r14
lea    0x8(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <delta_t@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %r15,%rdi
call   1030 <delta_t@plt>
cmp    %rbx,%r14
jbe    11e3 <compute_delta+0xa3>
mov    %r14,%rcx
cmp    %rax,%r14
jbe    11f5 <compute_delta+0xb5>
cmp    %rax,%rbx
cmova  %rbx,%rax
jmp    11f2 <compute_delta+0xb2>
mov    %rbx,%rcx
cmp    %rax,%rbx
jbe    11f5 <compute_delta+0xb5>
cmp    %rax,%r14
cmova  %r14,%rax
mov    %rax,%rcx
mov    %rcx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf7(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
define i64 @compute_delta() {
%1 = alloca i64
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = load i32, i32* @CLOCK_MONOTONIC
%10 = call i64 @clock_gettime(i32 %9, %struct.timespec* %2)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
%16 = load i32, i32* @CLOCK_MONOTONIC
%17 = call i64 @clock_gettime(i32 %16, %struct.timespec* %3)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %15
%23 = load i32, i32* @CLOCK_MONOTONIC
%24 = call i64 @clock_gettime(i32 %23, %struct.timespec* %4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %22
%30 = load i32, i32* @CLOCK_MONOTONIC
%31 = call i64 @clock_gettime(i32 %30, %struct.timespec* %5)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %29
%37 = call i64 @delta_t(%struct.timespec* %2, %struct.timespec* %3)
store i64 %37, i64* %6
%38 = call i64 @delta_t(%struct.timespec* %3, %struct.timespec* %4)
store i64 %38, i64* %7
%39 = call i64 @delta_t(%struct.timespec* %4, %struct.timespec* %5)
store i64 %39, i64* %8
%40 = load i64, i64* %6
%41 = load i64, i64* %7
%42 = icmp ule i64 %40, %41
br i1 %42, label %43, label %57
43: ; preds = %36
%44 = load i64, i64* %7
%45 = load i64, i64* %8
%46 = icmp ule i64 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = load i64, i64* %7
store i64 %48, i64* %1
br label %71
49: ; preds = %43
%50 = load i64, i64* %6
%51 = load i64, i64* %8
%52 = icmp ule i64 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = load i64, i64* %8
store i64 %54, i64* %1
br label %71
55: ; preds = %49
%56 = load i64, i64* %6
store i64 %56, i64* %1
br label %71
57: ; preds = %36
%58 = load i64, i64* %6
%59 = load i64, i64* %8
%60 = icmp ule i64 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %57
%62 = load i64, i64* %6
store i64 %62, i64* %1
br label %71
63: ; preds = %57
%64 = load i64, i64* %7
%65 = load i64, i64* %8
%66 = icmp ule i64 %64, %65
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = load i64, i64* %8
store i64 %68, i64* %1
br label %71
69: ; preds = %63
%70 = load i64, i64* %7
store i64 %70, i64* %1
br label %71
71: ; preds = %69, %67, %61, %55, %53, %47
%72 = load i64, i64* %1
ret i64 %72
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
define i64 @compute_delta() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %1 to i8*
%6 = bitcast %struct.timespec* %2 to i8*
%7 = bitcast %struct.timespec* %3 to i8*
%8 = bitcast %struct.timespec* %4 to i8*
%9 = load i32, i32* @CLOCK_MONOTONIC
%10 = call i64 @clock_gettime(i32 %9, %struct.timespec* %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %0
%16 = load i32, i32* @CLOCK_MONOTONIC
%17 = call i64 @clock_gettime(i32 %16, %struct.timespec* %2)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %15
%23 = load i32, i32* @CLOCK_MONOTONIC
%24 = call i64 @clock_gettime(i32 %23, %struct.timespec* %3)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %22
%30 = load i32, i32* @CLOCK_MONOTONIC
%31 = call i64 @clock_gettime(i32 %30, %struct.timespec* %4)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %29
%37 = call i64 @delta_t(%struct.timespec* %1, %struct.timespec* %2)
%38 = call i64 @delta_t(%struct.timespec* %2, %struct.timespec* %3)
%39 = call i64 @delta_t(%struct.timespec* %3, %struct.timespec* %4)
%40 = icmp ugt i64 %37, %38
br i1 %40, label %46, label %41
41: ; preds = %36
%42 = icmp ugt i64 %38, %39
br i1 %42, label %43, label %51
43: ; preds = %41
%44 = icmp ugt i64 %37, %39
%45 = select i1 %44, i64 %37, i64 %39
br label %51
46: ; preds = %36
%47 = icmp ugt i64 %37, %39
br i1 %47, label %48, label %51
48: ; preds = %46
%49 = icmp ugt i64 %38, %39
%50 = select i1 %49, i64 %38, i64 %39
br label %51
51: ; preds = %48, %46, %43, %41
%52 = phi i64 [ %38, %41 ], [ %45, %43 ], [ %37, %46 ], [ %50, %48 ]
ret i64 %52
}