#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 fanotify_response {
  int /*<<< orphan*/ response;
  int /*<<< orphan*/ fd;
};
struct fanotify_event_metadata {
  int /*<<< orphan*/ fd;
};
typedef int /*<<< orphan*/ response_struct;

/* Variables and functions */
int /*<<< orphan*/ FAN_ALLOW;
int write(int, struct fanotify_response *, int);
int handle_perm(int fan_fd, struct fanotify_event_metadata *metadata) {
  struct fanotify_response response_struct;
  int ret;
  response_struct.fd = metadata->fd;
  response_struct.response = FAN_ALLOW;
  ret = write(fan_fd, &response_struct, sizeof(response_struct));
  if (ret < 0)
    return ret;
  return 0;
}


x86 assembly (clang, -O0):
<handle_perm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    115d <handle_perm+0x4d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1164 <handle_perm+0x54>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_perm>:
push   %rax
mov    (%rsi),%eax
mov    %eax,0x4(%rsp)
mov    0x2ec2(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    %eax,%ecx
sar    $0x1f,%ecx
and    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.fanotify_event_metadata = type { i32 }
%struct.fanotify_response = type { i32, i32 }
@FAN_ALLOW = global i32 0
define i32 @handle_perm(i32 %0, %struct.fanotify_event_metadata* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.fanotify_event_metadata*
%6 = alloca %struct.fanotify_response
%7 = alloca i32
store i32 %0, i32* %4
store %struct.fanotify_event_metadata* %1, %struct.fanotify_event_metadata** %5
%8 = load %struct.fanotify_event_metadata*, %struct.fanotify_event_metadata** %5
%9 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.fanotify_response, %struct.fanotify_response* %6, i32 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @FAN_ALLOW
%13 = getelementptr inbounds %struct.fanotify_response, %struct.fanotify_response* %6, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* %4
%15 = call i32 @write(i32 %14, %struct.fanotify_response* %6, i32 8)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = load i32, i32* %7
store i32 %19, i32* %3
br label %21
20: ; preds = %2
store i32 0, i32* %3
br label %21
21: ; preds = %20, %18
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.fanotify_event_metadata = type { i32 }
%struct.fanotify_response = type { i32, i32 }
@FAN_ALLOW = global i32 0
define i32 @handle_perm(i32 %0, %struct.fanotify_event_metadata* nocapture %1) {
%3 = alloca %struct.fanotify_response
%4 = bitcast %struct.fanotify_response* %3 to i8*
%5 = getelementptr inbounds %struct.fanotify_event_metadata, %struct.fanotify_event_metadata* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.fanotify_response, %struct.fanotify_response* %3, i64 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @FAN_ALLOW
%9 = getelementptr inbounds %struct.fanotify_response, %struct.fanotify_response* %3, i64 0, i32 0
store i32 %8, i32* %9
%10 = call i32 @write(i32 %0, %struct.fanotify_response* %3, i32 8)
%11 = icmp slt i32 %10, 0
%12 = select i1 %11, i32 %10, i32 0
ret i32 %12
}