#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 event {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void keypadhandler(int fd, short event, void *arg) {
  fcntl(fd, F_SETFL, O_NONBLOCK);
  printf("i am here\n");
  struct event *ev = arg;
  printf("%d, %d, %d\n", fd, event, *(int *)arg);
  int ntowrite;
  char buf[3];
}


x86 assembly (clang, -O0):
<keypadhandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%esi
movswl -0x6(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keypadhandler>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    0x2e9c(%rip),%rax
mov    (%rax),%edx
call   1040 <fcntl@plt>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%ecx
lea    0xe98(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
%struct.event = type { i32 }
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str = [11 x i8] c"i am here\0A\00"
@.str.1 = [12 x i8] c"%d, %d, %d\0A\00"
define void @keypadhandler(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca %struct.event*
%8 = alloca i32
%9 = alloca [3 x i8]
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%10 = load i32, i32* %4
%11 = load i32, i32* @F_SETFL
%12 = load i32, i32* @O_NONBLOCK
%13 = call i32 @fcntl(i32 %10, i32 %11, i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%15 = load i8*, i8** %6
%16 = bitcast i8* %15 to %struct.event*
store %struct.event* %16, %struct.event** %7
%17 = load i32, i32* %4
%18 = load i16, i16* %5
%19 = sext i16 %18 to i32
%20 = load i8*, i8** %6
%21 = bitcast i8* %20 to i32*
%22 = load i32, i32* %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %19, i32 %22)
ret void
}

LLVM IR (-O2):
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [12 x i8] c"%d, %d, %d\0A\00"
@str = [10 x i8] c"i am here\00"
define void @keypadhandler(i32 %0, i16 signext %1, i8* nocapture %2) {
%4 = load i32, i32* @F_SETFL
%5 = load i32, i32* @O_NONBLOCK
%6 = tail call i32 @fcntl(i32 %0, i32 %4, i32 %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%8 = sext i16 %1 to i32
%9 = bitcast i8* %2 to i32*
%10 = load i32, i32* %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %8, i32 %10)
ret void
}