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

/* Variables and functions */
int /*<<< orphan*/ free(void *);
struct map_session_data *map_id2sd(int);
int /*<<< orphan*/ npc_event(struct map_session_data *, char const *);
int npc_event_timer(int tid, unsigned int tick, int id, int data) {
  struct map_session_data *sd = map_id2sd(id);
  if (sd == NULL)
    return 0;
  npc_event(sd, (const char *)data);
  free((void *)data);
  return 0;
}


x86 assembly (clang, -O0):
<npc_event_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <map_id2sd@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1167 <npc_event_timer+0x37>
movl   $0x0,-0x4(%rbp)
jmp    1184 <npc_event_timer+0x54>
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rsi
call   1050 <npc_event@plt>
movslq -0x14(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<npc_event_timer>:
push   %rbx
mov    %ecx,%ebx
mov    %edx,%edi
call   1040 <map_id2sd@plt>
test   %rax,%rax
je     1155 <npc_event_timer+0x25>
movslq %ebx,%rbx
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <npc_event@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.map_session_data = type { i32 }
define i32 @npc_event_timer(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.map_session_data*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* %8
%12 = call %struct.map_session_data* @map_id2sd(i32 %11)
store %struct.map_session_data* %12, %struct.map_session_data** %10
%13 = load %struct.map_session_data*, %struct.map_session_data** %10
%14 = icmp eq %struct.map_session_data* %13, null
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 0, i32* %5
br label %26
16: ; preds = %4
%17 = load %struct.map_session_data*, %struct.map_session_data** %10
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i8*
%21 = call i32 @npc_event(%struct.map_session_data* %17, i8* %20)
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
%25 = call i32 @free(i8* %24)
store i32 0, i32* %5
br label %26
26: ; preds = %16, %15
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
%struct.map_session_data = type { i32 }
define i32 @npc_event_timer(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call %struct.map_session_data* @map_id2sd(i32 %2)
%6 = icmp eq %struct.map_session_data* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = sext i32 %3 to i64
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @npc_event(%struct.map_session_data* %5, i8* %9)
%11 = tail call i32 @free(i8* %9)
br label %12
12: ; preds = %4, %7
ret i32 0
}