#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 crypt_backend_flags();
long time_ms(struct rusage *start, struct rusage *end) {
  int count_kernel_time = 0;
  long ms;
  if (crypt_backend_flags() & (1 << 0))
    count_kernel_time = 1;
  if (!end->ru_utime.tv_sec && !start->ru_utime.tv_sec &&
      !end->ru_utime.tv_usec && !start->ru_utime.tv_usec)
    count_kernel_time = 1;
  ms = (end->ru_utime.tv_sec - start->ru_utime.tv_sec) * 1000;
  ms += (end->ru_utime.tv_usec - start->ru_utime.tv_usec) / 1000;
  if (count_kernel_time) {
    ms += (end->ru_stime.tv_sec - start->ru_stime.tv_sec) * 1000;
    ms += (end->ru_stime.tv_usec - start->ru_stime.tv_usec) / 1000;
  }
  return ms;
}


x86 assembly (clang, -O0):
<time_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1030 <crypt_backend_flags@plt>
and    $0x1,%eax
cmp    $0x0,%eax
je     1141 <time_ms+0x31>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,0x8(%rax)
jne    1180 <time_ms+0x70>
mov    -0x8(%rbp),%rax
cmpl   $0x0,0x8(%rax)
jne    1180 <time_ms+0x70>
mov    -0x10(%rbp),%rax
cmpl   $0x0,0xc(%rax)
jne    1180 <time_ms+0x70>
mov    -0x8(%rbp),%rax
cmpl   $0x0,0xc(%rax)
jne    1180 <time_ms+0x70>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    -0x8(%rbp),%rcx
sub    0x8(%rcx),%eax
imul   $0x3e8,%eax,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    -0x8(%rbp),%rcx
sub    0xc(%rcx),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cltq
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1200 <time_ms+0xf0>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
imul   $0x3e8,%eax,%eax
cltq
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x8(%rbp),%rcx
sub    0x4(%rcx),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cltq
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_ms>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <crypt_backend_flags@plt>
and    $0x1,%eax
mov    0x8(%rbx),%ecx
mov    0x8(%r14),%edx
mov    %ecx,%esi
or     %edx,%esi
jne    1148 <time_ms+0x38>
cmpl   $0x0,0xc(%rbx)
jne    114a <time_ms+0x3a>
cmpl   $0x0,0xc(%r14)
mov    $0x1,%edx
cmove  %edx,%eax
jmp    114a <time_ms+0x3a>
mov    %edx,%ebp
sub    %ebp,%ecx
imul   $0x3e8,%ecx,%ecx
movslq %ecx,%rdx
mov    0xc(%rbx),%ecx
sub    0xc(%r14),%ecx
movslq %ecx,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rcx
add    %esi,%ecx
movslq %ecx,%rcx
add    %rdx,%rcx
test   %eax,%eax
je     11b3 <time_ms+0xa3>
movslq (%rbx),%rax
movslq (%r14),%rdx
sub    %rdx,%rax
imul   $0x3e8,%rax,%rax
mov    0x4(%rbx),%edx
sub    0x4(%r14),%edx
add    %rax,%rcx
movslq %edx,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
cltq
add    %rax,%rcx
mov    %rcx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
define i64 @time_ms(%struct.rusage* %0, %struct.rusage* %1) {
%3 = alloca %struct.rusage*
%4 = alloca %struct.rusage*
%5 = alloca i32
%6 = alloca i64
store %struct.rusage* %0, %struct.rusage** %3
store %struct.rusage* %1, %struct.rusage** %4
store i32 0, i32* %5
%7 = call i32 (...) @crypt_backend_flags()
%8 = and i32 %7, 1
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %5
br label %11
11: ; preds = %10, %2
%12 = load %struct.rusage*, %struct.rusage** %4
%13 = getelementptr inbounds %struct.rusage, %struct.rusage* %12, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %36, label %17
17: ; preds = %11
%18 = load %struct.rusage*, %struct.rusage** %3
%19 = getelementptr inbounds %struct.rusage, %struct.rusage* %18, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %36, label %23
23: ; preds = %17
%24 = load %struct.rusage*, %struct.rusage** %4
%25 = getelementptr inbounds %struct.rusage, %struct.rusage* %24, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %36, label %29
29: ; preds = %23
%30 = load %struct.rusage*, %struct.rusage** %3
%31 = getelementptr inbounds %struct.rusage, %struct.rusage* %30, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %29
store i32 1, i32* %5
br label %36
36: ; preds = %35, %29, %23, %17, %11
%37 = load %struct.rusage*, %struct.rusage** %4
%38 = getelementptr inbounds %struct.rusage, %struct.rusage* %37, i32 0, i32 1
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load %struct.rusage*, %struct.rusage** %3
%42 = getelementptr inbounds %struct.rusage, %struct.rusage* %41, i32 0, i32 1
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = sub nsw i32 %40, %44
%46 = mul nsw i32 %45, 1000
%47 = sext i32 %46 to i64
store i64 %47, i64* %6
%48 = load %struct.rusage*, %struct.rusage** %4
%49 = getelementptr inbounds %struct.rusage, %struct.rusage* %48, i32 0, i32 1
%50 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = load %struct.rusage*, %struct.rusage** %3
%53 = getelementptr inbounds %struct.rusage, %struct.rusage* %52, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = sub nsw i32 %51, %55
%57 = sdiv i32 %56, 1000
%58 = sext i32 %57 to i64
%59 = load i64, i64* %6
%60 = add nsw i64 %59, %58
store i64 %60, i64* %6
%61 = load i32, i32* %5
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %90
63: ; preds = %36
%64 = load %struct.rusage*, %struct.rusage** %4
%65 = getelementptr inbounds %struct.rusage, %struct.rusage* %64, i32 0, i32 0
%66 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = load %struct.rusage*, %struct.rusage** %3
%69 = getelementptr inbounds %struct.rusage, %struct.rusage* %68, i32 0, i32 0
%70 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = sub nsw i32 %67, %71
%73 = mul nsw i32 %72, 1000
%74 = sext i32 %73 to i64
%75 = load i64, i64* %6
%76 = add nsw i64 %75, %74
store i64 %76, i64* %6
%77 = load %struct.rusage*, %struct.rusage** %4
%78 = getelementptr inbounds %struct.rusage, %struct.rusage* %77, i32 0, i32 0
%79 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %78, i32 0, i32 1
%80 = load i32, i32* %79
%81 = load %struct.rusage*, %struct.rusage** %3
%82 = getelementptr inbounds %struct.rusage, %struct.rusage* %81, i32 0, i32 0
%83 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %82, i32 0, i32 1
%84 = load i32, i32* %83
%85 = sub nsw i32 %80, %84
%86 = sdiv i32 %85, 1000
%87 = sext i32 %86 to i64
%88 = load i64, i64* %6
%89 = add nsw i64 %88, %87
store i64 %89, i64* %6
br label %90
90: ; preds = %63, %36
%91 = load i64, i64* %6
ret i64 %91
}

LLVM IR (-O2):
%struct.rusage = type { %struct.TYPE_4__, %struct.TYPE_3__ }
%struct.TYPE_4__ = type { i32, i32 }
%struct.TYPE_3__ = type { i32, i32 }
define i64 @time_ms(%struct.rusage* nocapture %0, %struct.rusage* nocapture %1) {
%3 = tail call i32 (...) @crypt_backend_flags()
%4 = and i32 %3, 1
%5 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1, i32 0
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 0
%8 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 1, i32 0
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 0
%11 = select i1 %7, i1 %10, i1 false
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1, i32 1
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 1, i32 1
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i32 1, i32 %4
br label %21
21: ; preds = %16, %2, %12
%22 = phi i32 [ 0, %12 ], [ %9, %2 ], [ 0, %16 ]
%23 = phi i32 [ %4, %12 ], [ %4, %2 ], [ %20, %16 ]
%24 = sub nsw i32 %6, %22
%25 = mul nsw i32 %24, 1000
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 1, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 1, i32 1
%30 = load i32, i32* %29
%31 = sub nsw i32 %28, %30
%32 = sdiv i32 %31, 1000
%33 = sext i32 %32 to i64
%34 = add nsw i64 %33, %26
%35 = icmp eq i32 %23, 0
br i1 %35, label %53, label %36
36: ; preds = %21
%37 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 0
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 0, i32 0
%40 = load i32, i32* %39
%41 = sub nsw i32 %38, %40
%42 = mul nsw i32 %41, 1000
%43 = sext i32 %42 to i64
%44 = add nsw i64 %34, %43
%45 = getelementptr inbounds %struct.rusage, %struct.rusage* %1, i64 0, i32 0, i32 1
%46 = load i32, i32* %45
%47 = getelementptr inbounds %struct.rusage, %struct.rusage* %0, i64 0, i32 0, i32 1
%48 = load i32, i32* %47
%49 = sub nsw i32 %46, %48
%50 = sdiv i32 %49, 1000
%51 = sext i32 %50 to i64
%52 = add nsw i64 %44, %51
br label %53
53: ; preds = %36, %21
%54 = phi i64 [ %52, %36 ], [ %34, %21 ]
ret i64 %54
}