#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 unsigned int uint64_t;
struct timespec {
  unsigned int tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
void timespec_add_milli(struct timespec *ts, unsigned int ms) {
  uint64_t nsec = ts->tv_nsec;
  nsec += (ms * 1000);
  if (nsec > 1000000000) {
    ts->tv_sec++;
    ts->tv_nsec = nsec - 1000000000;
  } else {
    ts->tv_nsec = nsec;
  }
}


x86 assembly (clang, -O0):
<timespec_add_milli>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
imul   $0x3e8,-0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x3b9aca00,-0x10(%rbp)
jbe    114f <timespec_add_milli+0x4f>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%ecx
sub    $0x3b9aca00,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1158 <timespec_add_milli+0x58>
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_add_milli>:
imul   $0x3e8,%esi,%eax
add    (%rdi),%eax
cmp    $0x3b9aca01,%eax
jb     1118 <timespec_add_milli+0x18>
addl   $0x1,0x4(%rdi)
add    $0xc4653600,%eax
mov    %eax,(%rdi)
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define void @timespec_add_milli(%struct.timespec* %0, i32 %1) {
%3 = alloca %struct.timespec*
%4 = alloca i32
%5 = alloca i32
store %struct.timespec* %0, %struct.timespec** %3
store i32 %1, i32* %4
%6 = load %struct.timespec*, %struct.timespec** %3
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%8 = load i32, i32* %7
store i32 %8, i32* %5
%9 = load i32, i32* %4
%10 = mul i32 %9, 1000
%11 = load i32, i32* %5
%12 = add i32 %11, %10
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp ugt i32 %13, 1000000000
br i1 %14, label %15, label %24
15: ; preds = %2
%16 = load %struct.timespec*, %struct.timespec** %3
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
%20 = load i32, i32* %5
%21 = sub i32 %20, 1000000000
%22 = load %struct.timespec*, %struct.timespec** %3
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %22, i32 0, i32 0
store i32 %21, i32* %23
br label %28
24: ; preds = %2
%25 = load i32, i32* %5
%26 = load %struct.timespec*, %struct.timespec** %3
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %26, i32 0, i32 0
store i32 %25, i32* %27
br label %28
28: ; preds = %24, %15
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define void @timespec_add_milli(%struct.timespec* nocapture %0, i32 %1) {
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = mul i32 %1, 1000
%6 = add i32 %4, %5
%7 = icmp ugt i32 %6, 1000000000
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
store i32 %11, i32* %9
%12 = add i32 %6, -1000000000
br label %13
13: ; preds = %2, %8
%14 = phi i32 [ %12, %8 ], [ %6, %2 ]
store i32 %14, i32* %3
ret void
}