#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;
  int /*<<< orphan*/ time;
};

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


x86 assembly (clang, -O0):
<ftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    1157 <ftime+0x47>
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0xc(%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
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %eax,%eax
jne    114a <ftime+0x3a>
mov    0xc(%rsp),%ecx
mov    %ecx,0x4(%rbx)
movslq 0x8(%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timeb = type { i32, 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 i32 @gettimeofday(%struct.timeval* %2, i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %14
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 1
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
br label %14
14: ; preds = %6, %1
ret i32 %4
}