#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 */
typedef scalar_t__ time_t;
struct tm {
  int tm_gmtoff;
  int /*<<< orphan*/ tm_isdst;
};
struct timeb {
  int timezone;
  int /*<<< orphan*/ dstflag;
  int /*<<< orphan*/ time;
  scalar_t__ millitm;
};

/* Variables and functions */
int /*<<< orphan*/ *__localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ __set_errno(int);
int errno;
scalar_t__ time(int /*<<< orphan*/ *);
int ftime(struct timeb *timebuf) {
  int save = errno;
  struct tm tp;
  __set_errno(0);
  if (time(&timebuf->time) == (time_t)-1 && errno != 0)
    return -1;
  timebuf->millitm = 0;
  if (__localtime_r(&timebuf->time, &tp) == NULL)
    return -1;
  timebuf->timezone = tp.tm_gmtoff / 60;
  timebuf->dstflag = tp.tm_isdst;
  __set_errno(save);
  return 0;
}


x86 assembly (clang, -O0):
<ftime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
xor    %edi,%edi
call   1030 <__set_errno@plt>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1050 <time@plt>
cmp    $0xffffffffffffffff,%rax
jne    1182 <ftime+0x52>
mov    0x2e73(%rip),%rax
cmpl   $0x0,(%rax)
je     1182 <ftime+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <ftime+0xb1>
mov    -0x10(%rbp),%rax
movq   $0x0,0x10(%rax)
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
lea    -0x20(%rbp),%rsi
call   1040 <__localtime_r@plt>
cmp    $0x0,%rax
jne    11b5 <ftime+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <ftime+0xb1>
mov    -0x20(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%edi
call   1030 <__set_errno@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftime>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r15
mov    0x2e9a(%rip),%r12
mov    (%r12),%r14d
xor    %edi,%edi
call   1030 <__set_errno@plt>
lea    0x8(%r15),%rbx
mov    %rbx,%rdi
call   1050 <time@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffffffffffff,%rax
jne    116f <ftime+0x3f>
cmpl   $0x0,(%r12)
jne    11ba <ftime+0x8a>
movq   $0x0,0x10(%r15)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <__localtime_r@plt>
test   %rax,%rax
je     11ba <ftime+0x8a>
movslq 0x8(%rsp),%rax
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x5,%ecx
add    %eax,%ecx
mov    %ecx,(%r15)
mov    0xc(%rsp),%eax
mov    %eax,0x4(%r15)
mov    %r14d,%edi
call   1030 <__set_errno@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeb = type { i32, i32, i32, i64 }
%struct.tm = type { i32, i32 }
@errno = global i32 0
define i32 @ftime(%struct.timeb* %0) {
%2 = alloca i32
%3 = alloca %struct.timeb*
%4 = alloca i32
%5 = alloca %struct.tm
store %struct.timeb* %0, %struct.timeb** %3
%6 = load i32, i32* @errno
store i32 %6, i32* %4
%7 = call i32 @__set_errno(i32 0)
%8 = load %struct.timeb*, %struct.timeb** %3
%9 = getelementptr inbounds %struct.timeb, %struct.timeb* %8, i32 0, i32 2
%10 = call i64 @time(i32* %9)
%11 = icmp eq i64 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @errno
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 -1, i32* %2
br label %36
16: ; preds = %12, %1
%17 = load %struct.timeb*, %struct.timeb** %3
%18 = getelementptr inbounds %struct.timeb, %struct.timeb* %17, i32 0, i32 3
store i64 0, i64* %18
%19 = load %struct.timeb*, %struct.timeb** %3
%20 = getelementptr inbounds %struct.timeb, %struct.timeb* %19, i32 0, i32 2
%21 = call i32* @__localtime_r(i32* %20, %struct.tm* %5)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 -1, i32* %2
br label %36
24: ; preds = %16
%25 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%26 = load i32, i32* %25
%27 = sdiv i32 %26, 60
%28 = load %struct.timeb*, %struct.timeb** %3
%29 = getelementptr inbounds %struct.timeb, %struct.timeb* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
%31 = load i32, i32* %30
%32 = load %struct.timeb*, %struct.timeb** %3
%33 = getelementptr inbounds %struct.timeb, %struct.timeb* %32, i32 0, i32 1
store i32 %31, i32* %33
%34 = load i32, i32* %4
%35 = call i32 @__set_errno(i32 %34)
store i32 0, i32* %2
br label %36
36: ; preds = %24, %23, %15
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
%struct.timeb = type { i32, i32, i32, i64 }
%struct.tm = type { i32, i32 }
@errno = global i32 0
define i32 @ftime(%struct.timeb* %0) {
%2 = alloca %struct.tm
%3 = load i32, i32* @errno
%4 = bitcast %struct.tm* %2 to i8*
%5 = tail call i32 @__set_errno(i32 0)
%6 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 2
%7 = tail call i64 @time(i32* %6)
%8 = icmp eq i64 %7, -1
%9 = load i32, i32* @errno
%10 = icmp ne i32 %9, 0
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %25, label %12
12: ; preds = %1
%13 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 3
store i64 0, i64* %13
%14 = call i32* @__localtime_r(i32* %6, %struct.tm* %2)
%15 = icmp eq i32* %14, null
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = sdiv i32 %18, 60
%20 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 0
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.timeb, %struct.timeb* %0, i64 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @__set_errno(i32 %3)
br label %25
25: ; preds = %12, %1, %16
%26 = phi i32 [ 0, %16 ], [ -1, %1 ], [ -1, %12 ]
ret i32 %26
}