#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;
  scalar_t__ tv_sec;
};
struct link {
  int dummy;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int link_internal_sleep(struct link *, struct timeval *, int /*<<< orphan*/ *,
                        int, int);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int link_usleep_mask(struct link *link, int usec, sigset_t *mask, int reading,
                     int writing) {
  struct timeval tm;
  sigset_t emptymask;
  tm.tv_sec = 0;
  tm.tv_usec = usec;
  if (!mask) {
    sigemptyset(&emptymask);
    mask = &emptymask;
  }
  return link_internal_sleep(link, &tm, mask, reading, writing);
}


x86 assembly (clang, -O0):
<link_usleep_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1164 <link_usleep_mask+0x44>
lea    -0x34(%rbp),%rdi
call   1040 <sigemptyset@plt>
lea    -0x34(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    -0x30(%rbp),%rsi
call   1030 <link_internal_sleep@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<link_usleep_mask>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %rdi,%rbp
movq   $0x0,0x10(%rsp)
mov    %esi,0x8(%rsp)
test   %rdx,%rdx
jne    1155 <link_usleep_mask+0x35>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigemptyset@plt>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1030 <link_internal_sleep@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.link = type { i32 }
%struct.timeval = type { i32, i64 }
define i32 @link_usleep_mask(%struct.link* %0, i32 %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = bitcast %struct.timeval* %6 to i8*
%9 = bitcast i32* %7 to i8*
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
store i64 0, i64* %10
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
store i32 %1, i32* %11
%12 = icmp eq i32* %2, null
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = call i32 @sigemptyset(i32* %7)
br label %15
15: ; preds = %13, %5
%16 = phi i32* [ %2, %5 ], [ %7, %13 ]
%17 = call i32 @link_internal_sleep(%struct.link* %0, %struct.timeval* %6, i32* %16, i32 %3, i32 %4)
ret i32 %17
}