#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_time2posix(int /*<<< orphan*/, int *);
struct timeval *t2p_time2posix_timeval(struct timeval *tv) {
  int state;
  tv->tv_sec = t2p_time2posix(tv->tv_sec, &state);
  if (state == 1)
    tv->tv_usec >>= 1;
  else if (state == 2)
    tv->tv_usec = (tv->tv_usec + 1000000) >> 1;
  else if (state == -1) {
    tv->tv_usec <<= 1;
    t2p_normalize_timeval(tv);
  }
  return tv;
}


x86 assembly (clang, -O0):
<t2p_time2posix_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   1030 <t2p_time2posix@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
cmpl   $0x1,-0xc(%rbp)
jne    115f <t2p_time2posix_timeval+0x3f>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sar    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11ab <t2p_time2posix_timeval+0x8b>
cmpl   $0x2,-0xc(%rbp)
jne    1183 <t2p_time2posix_timeval+0x63>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0xf4240,%ecx
sar    $0x1,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11a6 <t2p_time2posix_timeval+0x86>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11a1 <t2p_time2posix_timeval+0x81>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <t2p_normalize_timeval@plt>
jmp    11a6 <t2p_time2posix_timeval+0x86>
jmp    11ab <t2p_time2posix_timeval+0x8b>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t2p_time2posix_timeval>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
lea    0xc(%rsp),%rsi
call   1030 <t2p_time2posix@plt>
mov    %eax,0x4(%rbx)
mov    0xc(%rsp),%eax
cmp    $0xffffffff,%eax
je     114f <t2p_time2posix_timeval+0x2f>
cmp    $0x2,%eax
je     115b <t2p_time2posix_timeval+0x3b>
cmp    $0x1,%eax
jne    1166 <t2p_time2posix_timeval+0x46>
sarl   (%rbx)
jmp    1166 <t2p_time2posix_timeval+0x46>
shll   (%rbx)
mov    %rbx,%rdi
call   1040 <t2p_normalize_timeval@plt>
jmp    1166 <t2p_time2posix_timeval+0x46>
mov    $0xf4240,%eax
add    (%rbx),%eax
sar    %eax
mov    %eax,(%rbx)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define %struct.timeval* @t2p_time2posix_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_time2posix(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 %17
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 = ashr i32 %15, 1
store i32 %16, i32* %14
br label %40
17: ; preds = %1
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load %struct.timeval*, %struct.timeval** %2
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1000000
%25 = ashr i32 %24, 1
%26 = load %struct.timeval*, %struct.timeval** %2
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %26, i32 0, i32 0
store i32 %25, i32* %27
br label %39
28: ; preds = %17
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load %struct.timeval*, %struct.timeval** %2
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = shl i32 %34, 1
store i32 %35, i32* %33
%36 = load %struct.timeval*, %struct.timeval** %2
%37 = call i32 @t2p_normalize_timeval(%struct.timeval* %36)
br label %38
38: ; preds = %31, %28
br label %39
39: ; preds = %38, %20
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_time2posix_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_time2posix(i32 %5, i32* %2)
store i32 %6, i32* %4
%7 = load i32, i32* %2
switch i32 %7, label %22 [
i32 1, label %8
i32 2, label %12
i32 -1, label %17
]
8: ; preds = %1
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%10 = load i32, i32* %9
%11 = ashr i32 %10, 1
store i32 %11, i32* %9
br label %22
12: ; preds = %1
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1000000
%16 = ashr i32 %15, 1
store i32 %16, i32* %13
br label %22
17: ; preds = %1
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%19 = load i32, i32* %18
%20 = shl i32 %19, 1
store i32 %20, i32* %18
%21 = call i32 @t2p_normalize_timeval(%struct.timeval* %0)
br label %22
22: ; preds = %1, %12, %17, %8
ret %struct.timeval* %0
}