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

/* Variables and functions */
int /*<<< orphan*/ t2p_normalize_timespec(struct timespec *);
int /*<<< orphan*/ t2p_posix2time(int /*<<< orphan*/, int *);
struct timespec *t2p_posix2time_timespec(struct timespec *ts) {
  int state;
  ts->tv_sec = t2p_posix2time(ts->tv_sec, &state);
  if (state == 1) {
    ts->tv_nsec <<= 1;
    t2p_normalize_timespec(ts);
  } else if (state == -1)
    ts->tv_nsec >>= 1;
  else if (state == -2)
    ts->tv_nsec = (ts->tv_nsec + 1000000000) >> 1;
  return ts;
}


x86 assembly (clang, -O0):
<t2p_posix2time_timespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0xc(%rbp),%rsi
call   1040 <t2p_posix2time@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
cmpl   $0x1,-0xc(%rbp)
jne    1168 <t2p_posix2time_timespec+0x48>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <t2p_normalize_timespec@plt>
jmp    11ab <t2p_posix2time_timespec+0x8b>
cmpl   $0xffffffff,-0xc(%rbp)
jne    1182 <t2p_posix2time_timespec+0x62>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sar    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11a6 <t2p_posix2time_timespec+0x86>
cmpl   $0xfffffffe,-0xc(%rbp)
jne    11a1 <t2p_posix2time_timespec+0x81>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0x3b9aca00,%ecx
sar    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11a6 <t2p_posix2time_timespec+0x86>
jmp    11ab <t2p_posix2time_timespec+0x8b>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t2p_posix2time_timespec>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
lea    0xc(%rsp),%rsi
call   1040 <t2p_posix2time@plt>
mov    %eax,0x4(%rbx)
mov    0xc(%rsp),%eax
cmp    $0xfffffffe,%eax
je     1157 <t2p_posix2time_timespec+0x37>
cmp    $0xffffffff,%eax
je     1164 <t2p_posix2time_timespec+0x44>
cmp    $0x1,%eax
jne    1166 <t2p_posix2time_timespec+0x46>
shll   (%rbx)
mov    %rbx,%rdi
call   1030 <t2p_normalize_timespec@plt>
jmp    1166 <t2p_posix2time_timespec+0x46>
mov    $0x3b9aca00,%eax
add    (%rbx),%eax
sar    %eax
mov    %eax,(%rbx)
jmp    1166 <t2p_posix2time_timespec+0x46>
sarl   (%rbx)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define %struct.timespec* @t2p_posix2time_timespec(%struct.timespec* %0) {
%2 = alloca %struct.timespec*
%3 = alloca i32
store %struct.timespec* %0, %struct.timespec** %2
%4 = load %struct.timespec*, %struct.timespec** %2
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%6 = load i32, i32* %5
%7 = call i32 @t2p_posix2time(i32 %6, i32* %3)
%8 = load %struct.timespec*, %struct.timespec** %2
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
store i32 %7, i32* %9
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %19
12: ; preds = %1
%13 = load %struct.timespec*, %struct.timespec** %2
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = shl i32 %15, 1
store i32 %16, i32* %14
%17 = load %struct.timespec*, %struct.timespec** %2
%18 = call i32 @t2p_normalize_timespec(%struct.timespec* %17)
br label %40
19: ; preds = %1
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load %struct.timespec*, %struct.timespec** %2
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = ashr i32 %25, 1
store i32 %26, i32* %24
br label %39
27: ; preds = %19
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, -2
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load %struct.timespec*, %struct.timespec** %2
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1000000000
%35 = ashr i32 %34, 1
%36 = load %struct.timespec*, %struct.timespec** %2
%37 = getelementptr inbounds %struct.timespec, %struct.timespec* %36, i32 0, i32 0
store i32 %35, i32* %37
br label %38
38: ; preds = %30, %27
br label %39
39: ; preds = %38, %22
br label %40
40: ; preds = %39, %12
%41 = load %struct.timespec*, %struct.timespec** %2
ret %struct.timespec* %41
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define %struct.timespec* @t2p_posix2time_timespec(%struct.timespec* returned %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%5 = load i32, i32* %4
%6 = call i32 @t2p_posix2time(i32 %5, i32* %2)
store i32 %6, i32* %4
%7 = load i32, i32* %2
switch i32 %7, label %22 [
i32 1, label %8
i32 -1, label %13
i32 -2, label %17
]
8: ; preds = %1
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%10 = load i32, i32* %9
%11 = shl i32 %10, 1
store i32 %11, i32* %9
%12 = call i32 @t2p_normalize_timespec(%struct.timespec* %0)
br label %22
13: ; preds = %1
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%15 = load i32, i32* %14
%16 = ashr i32 %15, 1
store i32 %16, i32* %14
br label %22
17: ; preds = %1
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1000000000
%21 = ashr i32 %20, 1
store i32 %21, i32* %18
br label %22
22: ; preds = %1, %13, %17, %8
ret %struct.timespec* %0
}