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

/* Variables and functions */
int /*<<< orphan*/ t2p_normalize_timeval(struct timeval *);
int /*<<< orphan*/ t2p_posix2time(int /*<<< orphan*/, int *);
struct timeval *t2p_posix2time_timeval(struct timeval *tv) {
  int state;
  tv->tv_sec = t2p_posix2time(tv->tv_sec, &state);
  if (state == 1) {
    tv->tv_usec <<= 1;
    t2p_normalize_timeval(tv);
  } else if (state == -1)
    tv->tv_usec >>= 1;
  else if (state == -2)
    tv->tv_usec = (tv->tv_usec + 1000000) >> 1;
  return tv;
}


x86 assembly (clang, -O0):
<t2p_posix2time_timeval>:
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_timeval+0x48>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <t2p_normalize_timeval@plt>
jmp    11ab <t2p_posix2time_timeval+0x8b>
cmpl   $0xffffffff,-0xc(%rbp)
jne    1182 <t2p_posix2time_timeval+0x62>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sar    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11a6 <t2p_posix2time_timeval+0x86>
cmpl   $0xfffffffe,-0xc(%rbp)
jne    11a1 <t2p_posix2time_timeval+0x81>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0xf4240,%ecx
sar    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11a6 <t2p_posix2time_timeval+0x86>
jmp    11ab <t2p_posix2time_timeval+0x8b>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t2p_posix2time_timeval>:
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_timeval+0x37>
cmp    $0xffffffff,%eax
je     1164 <t2p_posix2time_timeval+0x44>
cmp    $0x1,%eax
jne    1166 <t2p_posix2time_timeval+0x46>
shll   (%rbx)
mov    %rbx,%rdi
call   1030 <t2p_normalize_timeval@plt>
jmp    1166 <t2p_posix2time_timeval+0x46>
mov    $0xf4240,%eax
add    (%rbx),%eax
sar    %eax
mov    %eax,(%rbx)
jmp    1166 <t2p_posix2time_timeval+0x46>
sarl   (%rbx)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define %struct.timeval* @t2p_posix2time_timeval(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca i32
store %struct.timeval* %0, %struct.timeval** %2
%4 = load %struct.timeval*, %struct.timeval** %2
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%6 = load i32, i32* %5
%7 = call i32 @t2p_posix2time(i32 %6, i32* %3)
%8 = load %struct.timeval*, %struct.timeval** %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %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.timeval*, %struct.timeval** %2
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = shl i32 %15, 1
store i32 %16, i32* %14
%17 = load %struct.timeval*, %struct.timeval** %2
%18 = call i32 @t2p_normalize_timeval(%struct.timeval* %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.timeval*, %struct.timeval** %2
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %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.timeval*, %struct.timeval** %2
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1000000
%35 = ashr i32 %34, 1
%36 = load %struct.timeval*, %struct.timeval** %2
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %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.timeval*, %struct.timeval** %2
ret %struct.timeval* %41
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define %struct.timeval* @t2p_posix2time_timeval(%struct.timeval* returned %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %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.timeval, %struct.timeval* %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_timeval(%struct.timeval* %0)
br label %22
13: ; preds = %1
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %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.timeval, %struct.timeval* %0, i64 0, i32 0
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1000000
%21 = ashr i32 %20, 1
store i32 %21, i32* %18
br label %22
22: ; preds = %1, %13, %17, %8
ret %struct.timeval* %0
}