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

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
time_t __time(time_t *secs, unsigned long *nsecs) {
  struct timeval tv;
  if (gettimeofday(&tv, NULL) < 0) {
    return -1;
  }
  if (secs) {
    *secs = tv.tv_sec;
  }
  if (nsecs) {
    *nsecs = tv.tv_usec * 1000;
  }
  return tv.tv_sec;
}


x86 assembly (clang, -O0):
<__time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jge    1143 <__time+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    1179 <__time+0x69>
cmpq   $0x0,-0x10(%rbp)
je     1157 <__time+0x47>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1173 <__time+0x63>
imul   $0x3e8,-0x1c(%rbp),%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__time>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
js     114c <__time+0x3c>
test   %rbx,%rbx
je     1133 <__time+0x23>
mov    (%rsp),%eax
mov    %eax,(%rbx)
test   %r14,%r14
je     1147 <__time+0x37>
movslq 0x4(%rsp),%rax
imul   $0x3e8,%rax,%rax
mov    %rax,(%r14)
mov    (%rsp),%eax
jmp    1151 <__time+0x41>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @__time(i32* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64*
%6 = alloca %struct.timeval
store i32* %0, i32** %4
store i64* %1, i64** %5
%7 = call i64 @gettimeofday(%struct.timeval* %6, i32* null)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %29
10: ; preds = %2
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32*, i32** %4
store i32 %15, i32* %16
br label %17
17: ; preds = %13, %10
%18 = load i64*, i64** %5
%19 = icmp ne i64* %18, null
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%22 = load i32, i32* %21
%23 = mul nsw i32 %22, 1000
%24 = sext i32 %23 to i64
%25 = load i64*, i64** %5
store i64 %24, i64* %25
br label %26
26: ; preds = %20, %17
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%28 = load i32, i32* %27
store i32 %28, i32* %3
br label %29
29: ; preds = %26, %9
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @__time(i32* writeonly %0, i64* writeonly %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %2
%8 = icmp eq i32* %0, null
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* %0
br label %12
12: ; preds = %9, %7
%13 = icmp eq i64* %1, null
br i1 %13, label %19, label %14
14: ; preds = %12
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 1000
%18 = sext i32 %17 to i64
store i64 %18, i64* %1
br label %19
19: ; preds = %14, %12
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%21 = load i32, i32* %20
br label %22
22: ; preds = %2, %19
%23 = phi i32 [ %21, %19 ], [ -1, %2 ]
ret i32 %23
}