#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;
};
struct timespec {
  long tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ abort();
int errno;
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
void gettime(uint64_t *msec, struct timeval *ptv, struct timespec *pts) {
  struct timeval tv;
  if (0 != gettimeofday(&tv, NULL)) {
    do {
      printf("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/jam2in/arcus-misc/refs/heads/master/"
             "acp-c/common.c",
             61);
      abort();
    } while (0);
  }
  if (msec) {
    *msec = ((uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000);
  }
  if (ptv) {
    *ptv = tv;
  }
  if (pts) {
    pts->tv_sec = tv.tv_sec;
    pts->tv_nsec = (long)tv.tv_usec * 1000;
  }
}


x86 assembly (clang, -O0):
<gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11be <gettime+0x7e>
jmp    1174 <gettime+0x34>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
lea    0xe6a(%rip),%rdi
lea    0xe76(%rip),%rcx
mov    $0x3d,%r8d
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpq   $0x0,-0x8(%rbp)
je     11e7 <gettime+0xa7>
mov    -0x20(%rbp),%rax
imul   $0x3e8,%eax,%ecx
mov    -0x28(%rbp),%rax
mov    $0x3e8,%esi
cltd
idiv   %esi
add    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     1205 <gettime+0xc5>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    %rcx,0x8(%rax)
cmpq   $0x0,-0x18(%rbp)
je     122b <gettime+0xeb>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
imul   $0x3e8,-0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettime>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %rax,%rax
jne    11ba <gettime+0x7a>
test   %rbx,%rbx
je     118a <gettime+0x4a>
imul   $0x3e8,0x8(%rsp),%eax
movslq (%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
mov    %ecx,(%rbx)
test   %r14,%r14
je     1197 <gettime+0x57>
movups (%rsp),%xmm0
movups %xmm0,(%r14)
test   %r15,%r15
je     11b0 <gettime+0x70>
mov    0x8(%rsp),%rax
mov    %rax,0x8(%r15)
imul   $0x3e8,(%rsp),%rax
mov    %rax,(%r15)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e11(%rip),%rbx
mov    (%rbx),%edi
call   1060 <strerror@plt>
mov    (%rbx),%edx
lea    0xe2e(%rip),%rdi
lea    0xe3a(%rip),%rcx
mov    %rax,%rsi
mov    $0x3d,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
%struct.timespec = type { i64, i64 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [19 x i8] c" %s(%d) die %s:%d\0A\00"
@errno = global i32 0
@.str.2 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jam2in/arcus-misc/refs/heads/master/acp-c/common.c\00"
define void @gettime(i32* %0, %struct.timeval* %1, %struct.timespec* %2) {
%4 = alloca i32*
%5 = alloca %struct.timeval*
%6 = alloca %struct.timespec*
%7 = alloca %struct.timeval
store i32* %0, i32** %4
store %struct.timeval* %1, %struct.timeval** %5
store %struct.timespec* %2, %struct.timespec** %6
%8 = call i64 @gettimeofday(%struct.timeval* %7, i32* null)
%9 = icmp ne i64 0, %8
br i1 %9, label %10, label %19
10: ; preds = %3
br label %11
11: ; preds = %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = load i32, i32* @errno
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %15, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.2, i64 0, i64 0), i32 61)
%17 = call i32 (...) @abort()
unreachable
18: ; No predecessors!
br label %19
19: ; preds = %18, %3
%20 = load i32*, i32** %4
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%24 = load i64, i64* %23
%25 = trunc i64 %24 to i32
%26 = mul nsw i32 %25, 1000
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%28 = load i64, i64* %27
%29 = trunc i64 %28 to i32
%30 = sdiv i32 %29, 1000
%31 = add nsw i32 %26, %30
%32 = load i32*, i32** %4
store i32 %31, i32* %32
br label %33
33: ; preds = %22, %19
%34 = load %struct.timeval*, %struct.timeval** %5
%35 = icmp ne %struct.timeval* %34, null
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load %struct.timeval*, %struct.timeval** %5
%38 = bitcast %struct.timeval* %37 to i8*
%39 = bitcast %struct.timeval* %7 to i8*
br label %40
40: ; preds = %36, %33
%41 = load %struct.timespec*, %struct.timespec** %6
%42 = icmp ne %struct.timespec* %41, null
br i1 %42, label %43, label %53
43: ; preds = %40
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%45 = load i64, i64* %44
%46 = load %struct.timespec*, %struct.timespec** %6
%47 = getelementptr inbounds %struct.timespec, %struct.timespec* %46, i32 0, i32 1
store i64 %45, i64* %47
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%49 = load i64, i64* %48
%50 = mul nsw i64 %49, 1000
%51 = load %struct.timespec*, %struct.timespec** %6
%52 = getelementptr inbounds %struct.timespec, %struct.timespec* %51, i32 0, i32 0
store i64 %50, i64* %52
br label %53
53: ; preds = %43, %40
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
%struct.timespec = type { i64, i64 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [19 x i8] c" %s(%d) die %s:%d\0A\00"
@errno = global i32 0
@.str.2 = [141 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/jam2in/arcus-misc/refs/heads/master/acp-c/common.c\00"
define void @gettime(i32* writeonly %0, %struct.timeval* writeonly %1, %struct.timespec* writeonly %2) {
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %4 to i8*
%6 = call i64 @gettimeofday(%struct.timeval* %4, i32* null)
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = load i32, i32* @errno
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %12, i8* getelementptr inbounds ([141 x i8], [141 x i8]* @.str.2, i64 0, i64 0), i32 61)
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %3
%16 = icmp eq i32* %0, null
br i1 %16, label %27, label %17
17: ; preds = %15
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
%21 = mul nsw i32 %20, 1000
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%23 = load i64, i64* %22
%24 = trunc i64 %23 to i32
%25 = sdiv i32 %24, 1000
%26 = add nsw i32 %25, %21
store i32 %26, i32* %0
br label %27
27: ; preds = %17, %15
%28 = icmp eq %struct.timeval* %1, null
br i1 %28, label %31, label %29
29: ; preds = %27
%30 = bitcast %struct.timeval* %1 to i8*
br label %31
31: ; preds = %29, %27
%32 = icmp eq %struct.timespec* %2, null
br i1 %32, label %41, label %33
33: ; preds = %31
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%35 = load i64, i64* %34
%36 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %35, i64* %36
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%38 = load i64, i64* %37
%39 = mul nsw i64 %38, 1000
%40 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i64 %39, i64* %40
br label %41
41: ; preds = %33, %31
ret void
}