#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;
};

/* Variables and functions */
int errno;
int /*<<< orphan*/ exit(int);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ log_msg(char *);
int /*<<< orphan*/ printf(char *, char *, int, char *, int);
char *strerror(int);
uint64_t getmsec(void) {
  struct timeval tv;
  uint64_t msec;
  if (0 != gettimeofday(&tv, NULL)) {
    do {
      log_msg("gettimeofday");
      printf("%s(%d) die %s:%d\n", strerror(errno), errno,
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/naver/arcus-misc/refs/heads/master/mrr/"
             "mrr.c",
             98);
      exit(1);
    } while (0);
  }
  msec = ((uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000);
  return msec;
}


x86 assembly (clang, -O0):
<getmsec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11c1 <getmsec+0x71>
jmp    1178 <getmsec+0x28>
lea    0xe81(%rip),%rdi
call   1050 <log_msg@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
lea    0xe68(%rip),%rdi
lea    0xe73(%rip),%rcx
mov    $0x62,%r8d
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmsec>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
jne    118c <getmsec+0x3c>
imul   $0x3e8,0x8(%rsp),%ecx
movslq (%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe6d(%rip),%rdi
call   1050 <log_msg@plt>
mov    0x2e41(%rip),%rbx
mov    (%rbx),%edi
call   1070 <strerror@plt>
mov    (%rbx),%edx
lea    0xe5e(%rip),%rdi
lea    0xe69(%rip),%rcx
mov    %rax,%rsi
mov    $0x62,%r8d
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [18 x i8] c"%s(%d) die %s:%d\0A\00"
@errno = global i32 0
@.str.2 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/naver/arcus-misc/refs/heads/master/mrr/mrr.c\00"
define i32 @getmsec() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp ne i64 0, %3
br i1 %4, label %5, label %14
5: ; preds = %0
br label %6
6: ; preds = %5
%7 = call i32 @log_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = load i32, i32* @errno
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %10, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 98)
%12 = call i32 @exit(i32 1)
unreachable
13: ; No predecessors!
br label %14
14: ; preds = %13, %0
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = mul nsw i32 %17, 1000
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%20 = load i64, i64* %19
%21 = trunc i64 %20 to i32
%22 = sdiv i32 %21, 1000
%23 = add nsw i32 %18, %22
store i32 %23, i32* %2
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [18 x i8] c"%s(%d) die %s:%d\0A\00"
@errno = global i32 0
@.str.2 = [135 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/naver/arcus-misc/refs/heads/master/mrr/mrr.c\00"
define i32 @getmsec() {
%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
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = tail call i32 @log_msg(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = load i32, i32* @errno
%10 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32 %9, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.2, i64 0, i64 0), i32 98)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
%16 = mul nsw i32 %15, 1000
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
%20 = sdiv i32 %19, 1000
%21 = add nsw i32 %20, %16
ret i32 %21
}