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

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


x86 assembly (clang, -O0):
<ftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
lea    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jge    115f <ftime+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a1 <ftime+0x81>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,0x4(%rax)
mov    -0x30(%rbp),%rax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,0x6(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftime>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gettimeofday@plt>
test   %rax,%rax
js     1175 <ftime+0x65>
mov    0xc(%rsp),%eax
mov    %eax,0x8(%rbx)
movslq 0x8(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,(%rbx)
movzwl 0x18(%rsp),%eax
mov    %ax,0x4(%rbx)
movzwl 0x10(%rsp),%eax
mov    %ax,0x6(%rbx)
xor    %eax,%eax
jmp    117a <ftime+0x6a>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbx
ret

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

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