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

/* Variables and functions */
int /*<<< orphan*/ errno;
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
double stamp(void) {
  struct timeval tv;
  int res = gettimeofday(&tv, NULL);
  if (res) {
    printf("could not get time: %s", strerror(errno));
    return -1;
  }
  return (tv.tv_sec + tv.tv_usec / 1000000.0);
}


x86 assembly (clang, -O0):
<stamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1181 <stamp+0x51>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
movsd  0xe91(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a0 <stamp+0x70>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe6d(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stamp>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %eax,%eax
je     116e <stamp+0x3e>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xeb7(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
movsd  0xe97(%rip),%xmm0
add    $0x18,%rsp
ret
movsd  0x10(%rsp),%xmm0
divsd  0xe8c(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [23 x i8] c"could not get time: %s\00"
@errno = global i32 0
define double @stamp() {
%1 = alloca double
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
store i32 %4, i32* %3
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %9)
store double -1.000000e+00, double* %1
br label %18
11: ; preds = %0
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%13 = load double, double* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%15 = load double, double* %14
%16 = fdiv double %15, 1.000000e+06
%17 = fadd double %13, %16
store double %17, double* %1
br label %18
18: ; preds = %11, %7
%19 = load double, double* %1
ret double %19
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [23 x i8] c"could not get time: %s\00"
@errno = global i32 0
define double @stamp() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp eq i32 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %16
9: ; preds = %0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load double, double* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%13 = load double, double* %12
%14 = fdiv double %13, 1.000000e+06
%15 = fadd double %11, %14
br label %16
16: ; preds = %9, %5
%17 = phi double [ -1.000000e+00, %5 ], [ %15, %9 ]
ret double %17
}