#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int tv_sec;
  int tv_usec;
};
struct TYPE_3__ {
  int tv_sec;
  int tv_usec;
};
struct rusage {
  TYPE_2__ ru_stime;
  TYPE_1__ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ exit(int);
scalar_t__ getrusage(int /*<<< orphan*/, struct rusage *);
long ptime_ms(void) {
  long t;
  struct rusage info;
  if (getrusage(RUSAGE_SELF, &info))
    exit(1);
  t = (info.ru_utime.tv_sec + info.ru_stime.tv_sec) * 1000 +
      (info.ru_utime.tv_usec + info.ru_stime.tv_usec) / 1000;
  return (t);
}


x86 assembly (clang, -O0):
<ptime_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <getrusage@plt>
cmp    $0x0,%rax
je     114e <ptime_ms+0x2e>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%eax
add    -0x18(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptime_ms>:
sub    $0x18,%rsp
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <getrusage@plt>
test   %rax,%rax
jne    1173 <ptime_ms+0x53>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
add    0x10(%rsp),%eax
add    0x14(%rsp),%ecx
imul   $0x3e8,%eax,%eax
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
add    %eax,%ecx
movslq %ecx,%rax
add    $0x18,%rsp
ret
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@RUSAGE_SELF = global i32 0
define i64 @ptime_ms() {
%1 = alloca i64
%2 = alloca %struct.rusage
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i64 @getrusage(i32 %3, %struct.rusage* %2)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 1
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = add nsw i32 %11, %14
%16 = mul nsw i32 %15, 1000
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.rusage, %struct.rusage* %2, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = add nsw i32 %19, %22
%24 = sdiv i32 %23, 1000
%25 = add nsw i32 %16, %24
%26 = sext i32 %25 to i64
store i64 %26, i64* %1
%27 = load i64, i64* %1
ret i64 %27
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
@RUSAGE_SELF = global i32 0
define i64 @ptime_ms() {
%1 = alloca %struct.rusage
%2 = bitcast %struct.rusage* %1 to i8*
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i64 @getrusage(i32 %3, %struct.rusage* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, %10
%14 = mul nsw i32 %13, 1000
%15 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %18, %16
%20 = sdiv i32 %19, 1000
%21 = add nsw i32 %20, %14
%22 = sext i32 %21 to i64
ret i64 %22
}