#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_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
struct timeval *map_timeout(int poll_timeout, struct timeval *pSelTimeout) {
  struct timeval *pResult;
  assert(pSelTimeout != (struct timeval *)NULL);
  switch (poll_timeout) {
  case -1:
    pResult = (struct timeval *)NULL;
    break;
  case 0:
    pSelTimeout->tv_sec = 0;
    pSelTimeout->tv_usec = 0;
    pResult = pSelTimeout;
    break;
  default:
    pSelTimeout->tv_sec = poll_timeout / 1000;
    poll_timeout %= 1000;
    pSelTimeout->tv_usec = poll_timeout * 1000;
    pResult = pSelTimeout;
    break;
  }
  return pResult;
}


x86 assembly (clang, -O0):
<map_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
test   %rax,%rax
setne  %al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     1155 <map_timeout+0x45>
jmp    1145 <map_timeout+0x35>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     1162 <map_timeout+0x52>
jmp    1184 <map_timeout+0x74>
movq   $0x0,-0x18(%rbp)
jmp    11bb <map_timeout+0xab>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11bb <map_timeout+0xab>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
imul   $0x3e8,-0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<map_timeout>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1030 <assert@plt>
cmp    $0xffffffff,%ebp
je     1139 <map_timeout+0x29>
test   %ebp,%ebp
jne    113d <map_timeout+0x2d>
movl   $0x0,(%rbx)
xor    %eax,%eax
jmp    1164 <map_timeout+0x54>
xor    %ebx,%ebx
jmp    1167 <map_timeout+0x57>
movslq %ebp,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,(%rbx)
imul   $0x3e8,%eax,%eax
sub    %eax,%ebp
imul   $0x3e8,%ebp,%eax
mov    %eax,0x4(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define %struct.timeval* @map_timeout(i32 %0, %struct.timeval* %1) {
%3 = alloca i32
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
store i32 %0, i32* %3
store %struct.timeval* %1, %struct.timeval** %4
%6 = load %struct.timeval*, %struct.timeval** %4
%7 = icmp ne %struct.timeval* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %3
switch i32 %10, label %18 [
i32 -1, label %11
i32 0, label %12
]
11: ; preds = %2
store %struct.timeval* null, %struct.timeval** %5
br label %30
12: ; preds = %2
%13 = load %struct.timeval*, %struct.timeval** %4
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 0, i32* %14
%15 = load %struct.timeval*, %struct.timeval** %4
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i32 0, i32* %16
%17 = load %struct.timeval*, %struct.timeval** %4
store %struct.timeval* %17, %struct.timeval** %5
br label %30
18: ; preds = %2
%19 = load i32, i32* %3
%20 = sdiv i32 %19, 1000
%21 = load %struct.timeval*, %struct.timeval** %4
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %3
%24 = srem i32 %23, 1000
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = mul nsw i32 %25, 1000
%27 = load %struct.timeval*, %struct.timeval** %4
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 1
store i32 %26, i32* %28
%29 = load %struct.timeval*, %struct.timeval** %4
store %struct.timeval* %29, %struct.timeval** %5
br label %30
30: ; preds = %18, %12, %11
%31 = load %struct.timeval*, %struct.timeval** %5
ret %struct.timeval* %31
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define %struct.timeval* @map_timeout(i32 %0, %struct.timeval* writeonly %1) {
%3 = icmp ne %struct.timeval* %1, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
switch i32 %0, label %8 [
i32 -1, label %16
i32 0, label %6
]
6: ; preds = %2
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 0, i32* %7
br label %13
8: ; preds = %2
%9 = sdiv i32 %0, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 %9, i32* %10
%11 = srem i32 %0, 1000
%12 = mul nsw i32 %11, 1000
br label %13
13: ; preds = %6, %8
%14 = phi i32 [ %12, %8 ], [ 0, %6 ]
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i32 %14, i32* %15
br label %16
16: ; preds = %13, %2
%17 = phi %struct.timeval* [ null, %2 ], [ %1, %13 ]
ret %struct.timeval* %17
}