#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 {
  scalar_t__ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void set_timenow(struct timeval *tv) {
  if (gettimeofday(tv, NULL) == -1) {
    fprintf(stderr, "Error in gettimeofday(). Using inaccurate "
                    "time() instead\n");
    tv->tv_sec = time(NULL);
    tv->tv_usec = 0;
  }
}


x86 assembly (clang, -O0):
<set_timenow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    1184 <set_timenow+0x54>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_timenow>:
push   %rbx
mov    %rdi,%rbx
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cmp    $0xffffffff,%eax
je     1142 <set_timenow+0x12>
pop    %rbx
ret
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x8(%rbx)
movq   $0x0,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
@stderr = global i32 0
@.str = [58 x i8] c"Error in gettimeofday(). Using inaccurate time() instead\0A\00"
define void @set_timenow(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
store %struct.timeval* %0, %struct.timeval** %2
%3 = load %struct.timeval*, %struct.timeval** %2
%4 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @time(i32* null)
%10 = load %struct.timeval*, %struct.timeval** %2
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
store i32 %9, i32* %11
%12 = load %struct.timeval*, %struct.timeval** %2
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
store i64 0, i64* %13
br label %14
14: ; preds = %6, %1
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
@stderr = global i32 0
@.str = [58 x i8] c"Error in gettimeofday(). Using inaccurate time() instead\0A\00"
define void @set_timenow(%struct.timeval* nocapture %0) {
%2 = tail call i32 @gettimeofday(%struct.timeval* %0, i32* null)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @time(i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i64 0, i64* %9
br label %10
10: ; preds = %4, %1
ret void
}