#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 {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ notify_stop();
struct timeval *timer_get(struct timeval *);
struct timeval *timer_get_pending(struct timeval *timeout, int max_fd) {
  struct timeval *tvp;
  tvp = timer_get(timeout);
  if (!tvp && !max_fd) {
    timeout->tv_sec = timeout->tv_usec = 0;
    notify_stop();
    return timeout;
  }
  if (!tvp)
    return timeout;
  return tvp;
}


x86 assembly (clang, -O0):
<timer_get_pending>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <timer_get@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117c <timer_get_pending+0x5c>
cmpl   $0x0,-0x14(%rbp)
jne    117c <timer_get_pending+0x5c>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    $0x0,%al
call   1030 <notify_stop@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119c <timer_get_pending+0x7c>
cmpq   $0x0,-0x20(%rbp)
jne    1194 <timer_get_pending+0x74>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119c <timer_get_pending+0x7c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_get_pending>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <timer_get@plt>
test   %ebp,%ebp
jne    1145 <timer_get_pending+0x25>
test   %rax,%rax
jne    1145 <timer_get_pending+0x25>
xorps  %xmm0,%xmm0
movups %xmm0,(%rbx)
xor    %eax,%eax
call   1030 <notify_stop@plt>
jmp    114c <timer_get_pending+0x2c>
test   %rax,%rax
cmovne %rax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define %struct.timeval* @timer_get_pending(%struct.timeval* %0, i32 %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i32
%6 = alloca %struct.timeval*
store %struct.timeval* %0, %struct.timeval** %4
store i32 %1, i32* %5
%7 = load %struct.timeval*, %struct.timeval** %4
%8 = call %struct.timeval* @timer_get(%struct.timeval* %7)
store %struct.timeval* %8, %struct.timeval** %6
%9 = load %struct.timeval*, %struct.timeval** %6
%10 = icmp ne %struct.timeval* %9, null
br i1 %10, label %21, label %11
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = load %struct.timeval*, %struct.timeval** %4
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
store i64 0, i64* %16
%17 = load %struct.timeval*, %struct.timeval** %4
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
store i64 0, i64* %18
%19 = call i32 (...) @notify_stop()
%20 = load %struct.timeval*, %struct.timeval** %4
store %struct.timeval* %20, %struct.timeval** %3
br label %28
21: ; preds = %11, %2
%22 = load %struct.timeval*, %struct.timeval** %6
%23 = icmp ne %struct.timeval* %22, null
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = load %struct.timeval*, %struct.timeval** %4
store %struct.timeval* %25, %struct.timeval** %3
br label %28
26: ; preds = %21
%27 = load %struct.timeval*, %struct.timeval** %6
store %struct.timeval* %27, %struct.timeval** %3
br label %28
28: ; preds = %26, %24, %14
%29 = load %struct.timeval*, %struct.timeval** %3
ret %struct.timeval* %29
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define %struct.timeval* @timer_get_pending(%struct.timeval* %0, i32 %1) {
%3 = tail call %struct.timeval* @timer_get(%struct.timeval* %0)
%4 = icmp ne %struct.timeval* %3, null
%5 = icmp ne i32 %1, 0
%6 = or i1 %5, %4
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = bitcast %struct.timeval* %0 to i8*
%9 = tail call i32 (...) @notify_stop()
br label %12
10: ; preds = %2
%11 = select i1 %4, %struct.timeval* %3, %struct.timeval* %0
br label %12
12: ; preds = %10, %7
%13 = phi %struct.timeval* [ %0, %7 ], [ %11, %10 ]
ret %struct.timeval* %13
}