#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 {
  int tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
struct timeb {
  int millitm;
  scalar_t__ dstflag;
  scalar_t__ timezone;
  int /*<<< orphan*/ time;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int ftime(struct timeb *tp) {
  struct timespec ts;
  clock_gettime(CLOCK_REALTIME, &ts);
  tp->time = ts.tv_sec;
  tp->millitm = ts.tv_nsec / 1000000;
  tp->timezone = tp->dstflag = 0;
  return 0;
}


x86 assembly (clang, -O0):
<ftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x10(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x8(%rbp),%rax
movq   $0x0,0x10(%rax)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ec1(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    0xc(%rsp),%eax
mov    %eax,0x18(%rbx)
movslq 0x8(%rsp),%rax
imul   $0x431bde83,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
mov    %eax,(%rbx)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeb = type { i32, i64, i64, i32 }
%struct.timespec = type { i32, 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 i32, i32* @CLOCK_REALTIME
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %3)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%7 = load i32, i32* %6
%8 = load %struct.timeb*, %struct.timeb** %2
%9 = getelementptr inbounds %struct.timeb, %struct.timeb* %8, i32 0, i32 3
store i32 %7, i32* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%11 = load i32, i32* %10
%12 = sdiv i32 %11, 1000000
%13 = load %struct.timeb*, %struct.timeb** %2
%14 = getelementptr inbounds %struct.timeb, %struct.timeb* %13, i32 0, i32 0
store i32 %12, i32* %14
%15 = load %struct.timeb*, %struct.timeb** %2
%16 = getelementptr inbounds %struct.timeb, %struct.timeb* %15, i32 0, i32 1
store i64 0, i64* %16
%17 = load %struct.timeb*, %struct.timeb** %2
%18 = getelementptr inbounds %struct.timeb, %struct.timeb* %17, i32 0, i32 2
store i64 0, i64* %18
ret i32 0
}

LLVM IR (-O2):
%struct.timeb = type { i32, i64, i64, i32 }
%struct.timespec = type { i32, i32 }
@CLOCK_REALTIME = global i32 0
define i32 @ftime(%struct.timeb* nocapture writeonly %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = load i32, i32* @CLOCK_REALTIME
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %2)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 3
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 1000000
%12 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 0
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 1
%14 = bitcast i64* %13 to i8*
ret i32 0
}