#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__ const time_t;
struct timeval {
  int /*<<< orphan*/ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
scalar_t__ const time_sec_to_ms(int /*<<< orphan*/);
scalar_t__ const time_usec_to_ms(int /*<<< orphan*/);
time_t time_timeval_to_ms(struct timeval *timeval) {
  if (!timeval) {
    return 0;
  }
  const time_t sec_ms = time_sec_to_ms(timeval->tv_sec);
  const time_t usec_ms = time_usec_to_ms(timeval->tv_usec);
  return sec_ms + usec_ms;
}


x86 assembly (clang, -O0):
<time_timeval_to_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <time_timeval_to_ms+0x24>
movq   $0x0,-0x8(%rbp)
jmp    116f <time_timeval_to_ms+0x4f>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <time_sec_to_ms@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <time_usec_to_ms@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_timeval_to_ms>:
test   %rdi,%rdi
je     1149 <time_timeval_to_ms+0x29>
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
call   1040 <time_sec_to_ms@plt>
mov    %rax,%r14
mov    (%rbx),%edi
call   1030 <time_usec_to_ms@plt>
add    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i64 @time_timeval_to_ms(%struct.timeval* %0) {
%2 = alloca i64
%3 = alloca %struct.timeval*
%4 = alloca i64
%5 = alloca i64
store %struct.timeval* %0, %struct.timeval** %3
%6 = load %struct.timeval*, %struct.timeval** %3
%7 = icmp ne %struct.timeval* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i64 0, i64* %2
br label %21
9: ; preds = %1
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = call i64 @time_sec_to_ms(i32 %12)
store i64 %13, i64* %4
%14 = load %struct.timeval*, %struct.timeval** %3
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @time_usec_to_ms(i32 %16)
store i64 %17, i64* %5
%18 = load i64, i64* %4
%19 = load i64, i64* %5
%20 = add nsw i64 %18, %19
store i64 %20, i64* %2
br label %21
21: ; preds = %9, %8
%22 = load i64, i64* %2
ret i64 %22
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i64 @time_timeval_to_ms(%struct.timeval* %0) {
%2 = icmp eq %struct.timeval* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%5 = load i32, i32* %4
%6 = tail call i64 @time_sec_to_ms(i32 %5)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @time_usec_to_ms(i32 %8)
%10 = add nsw i64 %9, %6
br label %11
11: ; preds = %1, %3
%12 = phi i64 [ %10, %3 ], [ 0, %1 ]
ret i64 %12
}