#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 sigaction {
  void (*sa_handler)(int);
  scalar_t__ sa_flags;
  int /*<<< orphan*/ sa_mask;
};
typedef int __s32;

/* Variables and functions */
int FASYNC;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ F_SETOWN;
int /*<<< orphan*/ SIGIO;
int fcntl(int, int /*<<< orphan*/, ...);
int getpid();
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void axisAssignHandler(__s32 fd, void (*handler)(int)) {
  struct sigaction act;
  __s32 oflags;
  act.sa_handler = handler;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;
  sigaction(SIGIO, &act, NULL);
  fcntl(fd, F_SETOWN, getpid());
  oflags = fcntl(fd, F_GETFL);
  fcntl(fd, F_SETFL, oflags | FASYNC);
}


x86 assembly (clang, -O0):
<axisAssignHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
add    $0x10,%rdi
call   1060 <sigemptyset@plt>
movq   $0x0,-0x20(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    %eax,%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    -0x4(%rbp),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    -0x2c(%rbp),%edx
mov    0x2e0a(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<axisAssignHandler>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    %rsi,(%rsp)
lea    0x10(%rsp),%rdi
call   1060 <sigemptyset@plt>
movq   $0x0,0x8(%rsp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    0x2e28(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e2f(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fcntl@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i64, i32 }
@SIGIO = global i32 0
@F_SETOWN = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@FASYNC = global i32 0
define void @axisAssignHandler(i32 %0, void (i32)* %1) {
%3 = alloca i32
%4 = alloca void (i32)*
%5 = alloca %struct.sigaction
%6 = alloca i32
store i32 %0, i32* %3
store void (i32)* %1, void (i32)** %4
%7 = load void (i32)*, void (i32)** %4
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
store void (i32)* %7, void (i32)** %8
%9 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 2
%10 = call i32 @sigemptyset(i32* %9)
%11 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 1
store i64 0, i64* %11
%12 = load i32, i32* @SIGIO
%13 = call i32 @sigaction(i32 %12, %struct.sigaction* %5, i32* null)
%14 = load i32, i32* %3
%15 = load i32, i32* @F_SETOWN
%16 = call i32 (...) @getpid()
%17 = call i32 (i32, i32, ...) @fcntl(i32 %14, i32 %15, i32 %16)
%18 = load i32, i32* %3
%19 = load i32, i32* @F_GETFL
%20 = call i32 (i32, i32, ...) @fcntl(i32 %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %3
%22 = load i32, i32* @F_SETFL
%23 = load i32, i32* %6
%24 = load i32, i32* @FASYNC
%25 = or i32 %23, %24
%26 = call i32 (i32, i32, ...) @fcntl(i32 %21, i32 %22, i32 %25)
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i64, i32 }
@SIGIO = global i32 0
@F_SETOWN = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@FASYNC = global i32 0
define void @axisAssignHandler(i32 %0, void (i32)* %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store void (i32)* %1, void (i32)** %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 2
%7 = call i32 @sigemptyset(i32* %6)
%8 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i64 0, i64* %8
%9 = load i32, i32* @SIGIO
%10 = call i32 @sigaction(i32 %9, %struct.sigaction* %3, i32* null)
%11 = load i32, i32* @F_SETOWN
%12 = call i32 (...) @getpid()
%13 = call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %11, i32 %12)
%14 = load i32, i32* @F_GETFL
%15 = call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %14)
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* @FASYNC
%18 = or i32 %17, %15
%19 = call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %16, i32 %18)
ret void
}