#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 int uint64_t;
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
uint64_t hs_token_bucket_get_posix_time_usecs(void) {
  struct timeval tval = {
      0,
      0,
  };
  if (gettimeofday(&tval, NULL))
    return 0;
  return ((((uint64_t)tval.tv_sec) * 1000000) + ((uint64_t)tval.tv_usec));
}


x86 assembly (clang, -O0):
<hs_token_bucket_get_posix_time_usecs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
je     115b <hs_token_bucket_get_posix_time_usecs+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    116e <hs_token_bucket_get_posix_time_usecs+0x4e>
mov    -0x18(%rbp),%rax
imul   $0xf4240,%eax,%eax
mov    -0x20(%rbp),%rcx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hs_token_bucket_get_posix_time_usecs>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
imul   $0xf4240,0x8(%rsp),%ecx
add    (%rsp),%ecx
test   %rax,%rax
cmovne %ebx,%ecx
mov    %ecx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64, i32, i32 }
define i32 @hs_token_bucket_get_posix_time_usecs() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 0, i32* %1
br label %16
7: ; preds = %0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%9 = load i64, i64* %8
%10 = trunc i64 %9 to i32
%11 = mul nsw i32 %10, 1000000
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = add nsw i32 %11, %14
store i32 %15, i32* %1
br label %16
16: ; preds = %7, %6
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64, i32, i32 }
define i32 @hs_token_bucket_get_posix_time_usecs() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp eq i64 %3, 0
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%6 = load i64, i64* %5
%7 = trunc i64 %6 to i32
%8 = mul nsw i32 %7, 1000000
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
%12 = add nsw i32 %8, %11
%13 = select i1 %4, i32 %12, i32 0
ret i32 %13
}