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

/* Variables and functions */
int /*<<< orphan*/ TS_INFO_TIME_NOT_AVAILABLE;
int /*<<< orphan*/ TS_RESP_CTX_add_failure_info(struct TS_resp_ctx *,
                                                int /*<<< orphan*/);
int /*<<< orphan*/ TS_RESP_CTX_set_status_info(struct TS_resp_ctx *,
                                               int /*<<< orphan*/, char *);
int /*<<< orphan*/ TS_R_TIME_SYSCALL_ERROR;
int /*<<< orphan*/ TS_STATUS_REJECTION;
int /*<<< orphan*/ TSerror(int /*<<< orphan*/);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int def_time_cb(struct TS_resp_ctx *ctx, void *data, time_t *sec, long *usec) {
  struct timeval tv;
  if (gettimeofday(&tv, NULL) != 0) {
    TSerror(TS_R_TIME_SYSCALL_ERROR);
    TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
                                "Time is not available.");
    TS_RESP_CTX_add_failure_info(ctx, TS_INFO_TIME_NOT_AVAILABLE);
    return 0;
  }
  *sec = tv.tv_sec;
  *usec = tv.tv_usec;
  return 1;
}


x86 assembly (clang, -O0):
<def_time_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
je     11b4 <def_time_cb+0x74>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1060 <TSerror@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdx
call   1040 <TS_RESP_CTX_set_status_info@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
call   1050 <TS_RESP_CTX_add_failure_info@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cf <def_time_cb+0x8f>
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<def_time_cb>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rdi,%rbx
xor    %r14d,%r14d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
je     11a1 <def_time_cb+0x61>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1060 <TSerror@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdx
mov    %rbx,%rdi
call   1040 <TS_RESP_CTX_set_status_info@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <TS_RESP_CTX_add_failure_info@plt>
jmp    11b7 <def_time_cb+0x77>
mov    0x10(%rsp),%eax
mov    %eax,(%r12)
mov    0x8(%rsp),%rax
mov    %rax,(%r15)
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TS_resp_ctx = type { i32 }
%struct.timeval = type { i64, i32 }
@TS_R_TIME_SYSCALL_ERROR = global i32 0
@TS_STATUS_REJECTION = global i32 0
@.str = [23 x i8] c"Time is not available.\00"
@TS_INFO_TIME_NOT_AVAILABLE = global i32 0
define i32 @def_time_cb(%struct.TS_resp_ctx* %0, i8* %1, i32* %2, i64* %3) {
%5 = alloca i32
%6 = alloca %struct.TS_resp_ctx*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i64*
%10 = alloca %struct.timeval
store %struct.TS_resp_ctx* %0, %struct.TS_resp_ctx** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i64* %3, i64** %9
%11 = call i64 @gettimeofday(%struct.timeval* %10, i32* null)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %4
%14 = load i32, i32* @TS_R_TIME_SYSCALL_ERROR
%15 = call i32 @TSerror(i32 %14)
%16 = load %struct.TS_resp_ctx*, %struct.TS_resp_ctx** %6
%17 = load i32, i32* @TS_STATUS_REJECTION
%18 = call i32 @TS_RESP_CTX_set_status_info(%struct.TS_resp_ctx* %16, i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%19 = load %struct.TS_resp_ctx*, %struct.TS_resp_ctx** %6
%20 = load i32, i32* @TS_INFO_TIME_NOT_AVAILABLE
%21 = call i32 @TS_RESP_CTX_add_failure_info(%struct.TS_resp_ctx* %19, i32 %20)
store i32 0, i32* %5
br label %29
22: ; preds = %4
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%24 = load i32, i32* %23
%25 = load i32*, i32** %8
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load i64*, i64** %9
store i64 %27, i64* %28
store i32 1, i32* %5
br label %29
29: ; preds = %22, %13
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
%struct.TS_resp_ctx = type { i32 }
%struct.timeval = type { i64, i32 }
@TS_R_TIME_SYSCALL_ERROR = global i32 0
@TS_STATUS_REJECTION = global i32 0
@.str = [23 x i8] c"Time is not available.\00"
@TS_INFO_TIME_NOT_AVAILABLE = global i32 0
define i32 @def_time_cb(%struct.TS_resp_ctx* %0, i8* nocapture readnone %1, i32* nocapture writeonly %2, i64* nocapture writeonly %3) {
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %5 to i8*
%7 = call i64 @gettimeofday(%struct.timeval* %5, i32* null)
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = load i32, i32* @TS_R_TIME_SYSCALL_ERROR
%11 = tail call i32 @TSerror(i32 %10)
%12 = load i32, i32* @TS_STATUS_REJECTION
%13 = tail call i32 @TS_RESP_CTX_set_status_info(%struct.TS_resp_ctx* %0, i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @TS_INFO_TIME_NOT_AVAILABLE
%15 = tail call i32 @TS_RESP_CTX_add_failure_info(%struct.TS_resp_ctx* %0, i32 %14)
br label %21
16: ; preds = %4
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%18 = load i32, i32* %17
store i32 %18, i32* %2
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%20 = load i64, i64* %19
store i64 %20, i64* %3
br label %21
21: ; preds = %16, %9
%22 = phi i32 [ 0, %9 ], [ 1, %16 ]
ret i32 %22
}