#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 {
  long double tv_sec;
  long double tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ EX_OSERR;
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long double);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int main(void) {
  struct timespec before, after;
  long double delta_t;
  if (clock_gettime(CLOCK_REALTIME, &before) == -1)
    err(EX_OSERR, "clock_gettime() failed");
  sleep(3);
  if (clock_gettime(CLOCK_REALTIME, &after) == -1)
    err(EX_OSERR, "clock_gettime() failed");
  delta_t = (after.tv_sec - before.tv_sec) +
            (after.tv_nsec - before.tv_nsec) / (long double)1000000000;
  fprintf(stderr, "delta %.6Lf\n", delta_t);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    118f <main+0x3f>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1050 <err@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    11c9 <main+0x79>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1050 <err@plt>
fldt   -0x50(%rbp)
fldt   -0x30(%rbp)
fsubrp %st,%st(1)
fldt   -0x40(%rbp)
fldt   -0x20(%rbp)
fsubrp %st,%st(1)
flds   0xe21(%rip)
fdivrp %st,%st(1)
faddp  %st,%st(1)
fstpt  -0x60(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
fldt   -0x60(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xe1d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x50,%rsp
mov    0x2e7c(%rip),%rbx
mov    (%rbx),%edi
lea    0x30(%rsp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    1182 <main+0x32>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1050 <err@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    11b2 <main+0x62>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1050 <err@plt>
fldt   0x10(%rsp)
fldt   0x20(%rsp)
fldt   0x40(%rsp)
fsubrp %st,%st(1)
fldt   0x30(%rsp)
fxch   %st(1)
fdivs  0xe34(%rip)
fxch   %st(2)
fsubp  %st,%st(1)
faddp  %st,%st(1)
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
fstpt  (%rsp)
lea    0xe36(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { x86_fp80, x86_fp80 }
@CLOCK_REALTIME = global i32 0
@EX_OSERR = global i32 0
@.str = [23 x i8] c"clock_gettime() failed\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"delta %.6Lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca x86_fp80
store i32 0, i32* %1
%5 = load i32, i32* @CLOCK_REALTIME
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @EX_OSERR
%10 = call i32 @err(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %0
%12 = call i32 @sleep(i32 3)
%13 = load i32, i32* @CLOCK_REALTIME
%14 = call i32 @clock_gettime(i32 %13, %struct.timespec* %3)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @EX_OSERR
%18 = call i32 @err(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %11
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%21 = load x86_fp80, x86_fp80* %20
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%23 = load x86_fp80, x86_fp80* %22
%24 = fsub x86_fp80 %21, %23
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%26 = load x86_fp80, x86_fp80* %25
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%28 = load x86_fp80, x86_fp80* %27
%29 = fsub x86_fp80 %26, %28
%30 = fdiv x86_fp80 %29, 0xK401CEE6B280000000000
%31 = fadd x86_fp80 %24, %30
store x86_fp80 %31, x86_fp80* %4
%32 = load i32, i32* @stderr
%33 = load x86_fp80, x86_fp80* %4
%34 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), x86_fp80 %33)
%35 = load i32, i32* @EXIT_SUCCESS
%36 = call i32 @exit(i32 %35)
unreachable
}

LLVM IR (-O2):
%struct.timespec = type { x86_fp80, x86_fp80 }
@CLOCK_REALTIME = global i32 0
@EX_OSERR = global i32 0
@.str = [23 x i8] c"clock_gettime() failed\00"
@stderr = global i32 0
@.str.1 = [13 x i8] c"delta %.6Lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.timespec* %2 to i8*
%5 = load i32, i32* @CLOCK_REALTIME
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @EX_OSERR
%10 = call i32 @err(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %8, %0
%12 = call i32 @sleep(i32 3)
%13 = load i32, i32* @CLOCK_REALTIME
%14 = call i32 @clock_gettime(i32 %13, %struct.timespec* %2)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @EX_OSERR
%18 = call i32 @err(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %11
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%21 = load x86_fp80, x86_fp80* %20
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%23 = load x86_fp80, x86_fp80* %22
%24 = fsub x86_fp80 %21, %23
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%26 = load x86_fp80, x86_fp80* %25
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%28 = load x86_fp80, x86_fp80* %27
%29 = fsub x86_fp80 %26, %28
%30 = fdiv x86_fp80 %29, 0xK401CEE6B280000000000
%31 = fadd x86_fp80 %24, %30
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), x86_fp80 %31)
%34 = load i32, i32* @EXIT_SUCCESS
%35 = call i32 @exit(i32 %34)
unreachable
}