#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_F_DEF_TIME_CB;
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*/ TSerr(int /*<<< orphan*/, 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) {
    TSerr(TS_F_DEF_TIME_CB, 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   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     11bd <def_time_cb+0x7d>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1030 <TSerr@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe66(%rip),%rdx
call   1050 <TS_RESP_CTX_set_status_info@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1060 <TS_RESP_CTX_add_failure_info@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <def_time_cb+0x98>
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   1040 <gettimeofday@plt>
test   %rax,%rax
je     11aa <def_time_cb+0x6a>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1030 <TSerr@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe71(%rip),%rdx
mov    %rbx,%rdi
call   1050 <TS_RESP_CTX_set_status_info@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <TS_RESP_CTX_add_failure_info@plt>
jmp    11c0 <def_time_cb+0x80>
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_F_DEF_TIME_CB = global i32 0
@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 %23
13: ; preds = %4
%14 = load i32, i32* @TS_F_DEF_TIME_CB
%15 = load i32, i32* @TS_R_TIME_SYSCALL_ERROR
%16 = call i32 @TSerr(i32 %14, i32 %15)
%17 = load %struct.TS_resp_ctx*, %struct.TS_resp_ctx** %6
%18 = load i32, i32* @TS_STATUS_REJECTION
%19 = call i32 @TS_RESP_CTX_set_status_info(%struct.TS_resp_ctx* %17, i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%20 = load %struct.TS_resp_ctx*, %struct.TS_resp_ctx** %6
%21 = load i32, i32* @TS_INFO_TIME_NOT_AVAILABLE
%22 = call i32 @TS_RESP_CTX_add_failure_info(%struct.TS_resp_ctx* %20, i32 %21)
store i32 0, i32* %5
br label %30
23: ; preds = %4
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load i32*, i32** %8
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%28 = load i64, i64* %27
%29 = load i64*, i64** %9
store i64 %28, i64* %29
store i32 1, i32* %5
br label %30
30: ; preds = %23, %13
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
%struct.TS_resp_ctx = type { i32 }
%struct.timeval = type { i64, i32 }
@TS_F_DEF_TIME_CB = global i32 0
@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 %17, label %9
9: ; preds = %4
%10 = load i32, i32* @TS_F_DEF_TIME_CB
%11 = load i32, i32* @TS_R_TIME_SYSCALL_ERROR
%12 = tail call i32 @TSerr(i32 %10, i32 %11)
%13 = load i32, i32* @TS_STATUS_REJECTION
%14 = tail call i32 @TS_RESP_CTX_set_status_info(%struct.TS_resp_ctx* %0, i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @TS_INFO_TIME_NOT_AVAILABLE
%16 = tail call i32 @TS_RESP_CTX_add_failure_info(%struct.TS_resp_ctx* %0, i32 %15)
br label %22
17: ; preds = %4
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%19 = load i32, i32* %18
store i32 %19, i32* %2
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%21 = load i64, i64* %20
store i64 %21, i64* %3
br label %22
22: ; preds = %17, %9
%23 = phi i32 [ 0, %9 ], [ 1, %17 ]
ret i32 %23
}