#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 timespec {
  unsigned long long tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
struct timeb {
  unsigned long long millitm;
  int /*<<< orphan*/ time;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ libc_ftime(struct timeb *);
int /*<<< orphan*/ syscall(int, int /*<<< orphan*/, struct timespec *);
__attribute__((visibility("default"))) int ftime(struct timeb *tp) {
  if (tp) {
    libc_ftime(tp);
    struct timespec ts;
    syscall(228, CLOCK_REALTIME, &ts);
    tp->time = ts.tv_sec;
    tp->millitm = ts.tv_nsec / 1000000ULL;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1179 <ftime+0x59>
mov    -0x8(%rbp),%rdi
call   1040 <libc_ftime@plt>
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
mov    $0xe4,%edi
lea    -0x18(%rbp),%rdx
call   1030 <syscall@plt>
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftime>:
test   %rdi,%rdi
je     1169 <ftime+0x49>
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <libc_ftime@plt>
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    $0xe4,%edi
call   1030 <syscall@plt>
mov    0x8(%rsp),%eax
mov    %eax,0x8(%rbx)
movabs $0x431bde82d7b634db,%rax
de 1b 43
mulq   (%rsp)
shr    $0x12,%rdx
mov    %rdx,(%rbx)
add    $0x10,%rsp
pop    %rbx
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.timeb = type { i64, i32 }
%struct.timespec = type { i64, i32 }
@CLOCK_REALTIME = global i32 0
define i32 @ftime(%struct.timeb* %0) {
%2 = alloca %struct.timeb*
%3 = alloca %struct.timespec
store %struct.timeb* %0, %struct.timeb** %2
%4 = load %struct.timeb*, %struct.timeb** %2
%5 = icmp ne %struct.timeb* %4, null
br i1 %5, label %6, label %20
6: ; preds = %1
%7 = load %struct.timeb*, %struct.timeb** %2
%8 = call i32 @libc_ftime(%struct.timeb* %7)
%9 = load i32, i32* @CLOCK_REALTIME
%10 = call i32 @syscall(i32 228, i32 %9, %struct.timespec* %3)
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%12 = load i32, i32* %11
%13 = load %struct.timeb*, %struct.timeb** %2
%14 = getelementptr inbounds %struct.timeb, %struct.timeb* %13, i32 0, i32 1
store i32 %12, i32* %14
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%16 = load i64, i64* %15
%17 = udiv i64 %16, 1000000
%18 = load %struct.timeb*, %struct.timeb** %2
%19 = getelementptr inbounds %struct.timeb, %struct.timeb* %18, i32 0, i32 0
store i64 %17, i64* %19
br label %20
20: ; preds = %6, %1
ret i32 0
}

LLVM IR (-O2):
%struct.timeb = type { i64, i32 }
%struct.timespec = type { i64, i32 }
@CLOCK_REALTIME = global i32 0
define i32 @ftime(%struct.timeb* %0) {
%2 = alloca %struct.timespec
%3 = icmp eq %struct.timeb* %0, null
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i32 @libc_ftime(%struct.timeb* %0)
%6 = bitcast %struct.timespec* %2 to i8*
%7 = load i32, i32* @CLOCK_REALTIME
%8 = call i32 @syscall(i32 228, i32 %7, %struct.timespec* %2)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 1
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%13 = load i64, i64* %12
%14 = udiv i64 %13, 1000000
%15 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 0
store i64 %14, i64* %15
br label %16
16: ; preds = %4, %1
ret i32 0
}