#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 timezone {
  int tz_minuteswest;
};
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ error_exit(int /*<<< orphan*/);
int /*<<< orphan*/ gettext(char *);
int gettimeofday(struct timeval *, struct timezone *);
double get_ts(void) {
  struct timeval ts;
  struct timezone tz;
  if (gettimeofday(&ts, &tz) == -1)
    error_exit(gettext("gettimeofday failed"));
  return (double)ts.tv_sec + ((double)ts.tv_usec) / 1000000.0 +
         (double)(tz.tz_minuteswest * 60);
}


x86 assembly (clang, -O0):
<get_ts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    1161 <get_ts+0x31>
lea    0xeb3(%rip),%rdi
call   1030 <gettext@plt>
mov    %eax,%edi
call   1050 <error_exit@plt>
cvtsi2sdq -0x8(%rbp),%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
movsd  0xe8b(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
imul   $0x3c,-0x18(%rbp),%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ts>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    1159 <get_ts+0x29>
lea    0xebb(%rip),%rdi
call   1030 <gettext@plt>
mov    %eax,%edi
call   1050 <error_exit@plt>
cvtsi2sdq 0x10(%rsp),%xmm0
cvtsi2sdq 0x8(%rsp),%xmm1
divsd  0xe91(%rip),%xmm1
imul   $0x3c,(%rsp),%eax
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
@.str = [20 x i8] c"gettimeofday failed\00"
define double @get_ts() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timezone
%3 = call i32 @gettimeofday(%struct.timeval* %1, %struct.timezone* %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @gettext(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @error_exit(i32 %6)
br label %8
8: ; preds = %5, %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%10 = load i64, i64* %9
%11 = sitofp i64 %10 to double
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = fdiv double %14, 1.000000e+06
%16 = fadd double %11, %15
%17 = getelementptr inbounds %struct.timezone, %struct.timezone* %2, i32 0, i32 0
%18 = load i32, i32* %17
%19 = mul nsw i32 %18, 60
%20 = sitofp i32 %19 to double
%21 = fadd double %16, %20
ret double %21
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
@.str = [20 x i8] c"gettimeofday failed\00"
define double @get_ts() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timezone
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timezone* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %1, %struct.timezone* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @gettext(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @error_exit(i32 %8)
br label %10
10: ; preds = %7, %0
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%15 = load i64, i64* %14
%16 = sitofp i64 %15 to double
%17 = fdiv double %16, 1.000000e+06
%18 = fadd double %17, %13
%19 = getelementptr inbounds %struct.timezone, %struct.timezone* %2, i64 0, i32 0
%20 = load i32, i32* %19
%21 = mul nsw i32 %20, 60
%22 = sitofp i32 %21 to double
%23 = fadd double %18, %22
ret double %23
}