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

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int ftime(struct timeb *tp) {
  struct timeval tv;
  if (gettimeofday(&tv, NULL) < 0) {
    return -1;
  }
  tp->time = tv.tv_sec;
  tp->millitm = tv.tv_usec / 1000;
  tp->timezone = 0;
  tp->dstflag = 0;
  return 0;
}


x86 assembly (clang, -O0):
<ftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jge    113f <ftime+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    117b <ftime+0x6b>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftime>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %r14d,%r14d
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
js     1153 <ftime+0x43>
mov    0x4(%rsp),%eax
mov    %eax,0x18(%rbx)
movslq (%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,(%rbx)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rbx)
jmp    1159 <ftime+0x49>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeb = type { i32, i64, i64, i32 }
%struct.timeval = type { i32, i32 }
define i32 @ftime(%struct.timeb* %0) {
%2 = alloca i32
%3 = alloca %struct.timeb*
%4 = alloca %struct.timeval
store %struct.timeb* %0, %struct.timeb** %3
%5 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %22
8: ; preds = %1
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%10 = load i32, i32* %9
%11 = load %struct.timeb*, %struct.timeb** %3
%12 = getelementptr inbounds %struct.timeb, %struct.timeb* %11, i32 0, i32 3
store i32 %10, i32* %12
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 1000
%16 = load %struct.timeb*, %struct.timeb** %3
%17 = getelementptr inbounds %struct.timeb, %struct.timeb* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = load %struct.timeb*, %struct.timeb** %3
%19 = getelementptr inbounds %struct.timeb, %struct.timeb* %18, i32 0, i32 2
store i64 0, i64* %19
%20 = load %struct.timeb*, %struct.timeb** %3
%21 = getelementptr inbounds %struct.timeb, %struct.timeb* %20, i32 0, i32 1
store i64 0, i64* %21
store i32 0, i32* %2
br label %22
22: ; preds = %8, %7
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.timeb = type { i32, i64, i64, i32 }
%struct.timeval = type { i32, i32 }
define i32 @ftime(%struct.timeb* nocapture writeonly %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = icmp slt i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 3
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = sdiv i32 %11, 1000
%13 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 0
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 1
%15 = bitcast i64* %14 to i8*
br label %16
16: ; preds = %1, %6
%17 = phi i32 [ 0, %6 ], [ -1, %1 ]
ret i32 %17
}