#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 */
int gettimeofday(struct timeval *, struct timezone *);
int ftime(struct timeb *tp) {
  struct timeval tv;
  struct timezone tz;
  int ret = gettimeofday(&tv, &tz);
  tp->time = tv.tv_sec;
  tp->millitm = tv.tv_usec / 1000;
  tp->timezone = tz.tz_minuteswest;
  tp->dstflag = tz.tz_dsttime;
  return ret;
}


x86 assembly (clang, -O0):
<ftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <gettimeofday@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x10(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <gettimeofday@plt>
mov    0xc(%rsp),%ecx
mov    %ecx,0xc(%rbx)
movslq 0x8(%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,(%rbx)
mov    0x4(%rsp),%ecx
mov    %ecx,0x8(%rbx)
mov    (%rsp),%ecx
mov    %ecx,0x4(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timeb = type { i32, i32, i32, i32 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { 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 i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%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.timezone, %struct.timezone* %3, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.timezone, %struct.timezone* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 1
store i32 %18, i32* %19
ret i32 %6
}