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

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


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

x86 assembly (clang, -O2):
<ftime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1030 <gettimeofday@plt>
test   %rax,%rax
js     115d <ftime+0x4d>
movslq (%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,(%rbx)
mov    0x4(%rsp),%eax
mov    %eax,0xc(%rbx)
mov    0xc(%rsp),%eax
mov    %eax,0x8(%rbx)
mov    0x8(%rsp),%eax
mov    %eax,0x4(%rbx)
xor    %eax,%eax
jmp    1162 <ftime+0x52>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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