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

/* Variables and functions */
int /*<<< orphan*/ hook_add_to_infolist(struct t_infolist *, void *,
                                        char const *);
int /*<<< orphan*/ hook_valid(void *);
int /*<<< orphan*/ infolist_free(struct t_infolist *);
struct t_infolist *infolist_new(int /*<<< orphan*/ *);
struct t_infolist *plugin_api_infolist_hook_cb(void *data,
                                               const char *infolist_name,
                                               void *pointer,
                                               const char *arguments) {
  struct t_infolist *ptr_infolist;
  (void)data;
  (void)infolist_name;
  if (pointer && !hook_valid(pointer))
    return NULL;
  ptr_infolist = infolist_new(NULL);
  if (!ptr_infolist)
    return NULL;
  if (!hook_add_to_infolist(ptr_infolist, pointer, arguments)) {
    infolist_free(ptr_infolist);
    return NULL;
  }
  return ptr_infolist;
}


x86 assembly (clang, -O0):
<plugin_api_infolist_hook_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1182 <plugin_api_infolist_hook_cb+0x42>
mov    -0x20(%rbp),%rdi
call   1030 <hook_valid@plt>
cmp    $0x0,%eax
jne    1182 <plugin_api_infolist_hook_cb+0x42>
movq   $0x0,-0x8(%rbp)
jmp    11df <plugin_api_infolist_hook_cb+0x9f>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <infolist_new@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a7 <plugin_api_infolist_hook_cb+0x67>
movq   $0x0,-0x8(%rbp)
jmp    11df <plugin_api_infolist_hook_cb+0x9f>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <hook_add_to_infolist@plt>
cmp    $0x0,%eax
jne    11d7 <plugin_api_infolist_hook_cb+0x97>
mov    -0x30(%rbp),%rdi
call   1050 <infolist_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11df <plugin_api_infolist_hook_cb+0x9f>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plugin_api_infolist_hook_cb>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
test   %rdx,%rdx
je     115f <plugin_api_infolist_hook_cb+0x1f>
mov    %rbx,%rdi
call   1030 <hook_valid@plt>
test   %eax,%eax
je     1190 <plugin_api_infolist_hook_cb+0x50>
xor    %r15d,%r15d
xor    %edi,%edi
call   1040 <infolist_new@plt>
test   %rax,%rax
je     1193 <plugin_api_infolist_hook_cb+0x53>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <hook_add_to_infolist@plt>
test   %eax,%eax
je     1188 <plugin_api_infolist_hook_cb+0x48>
mov    %r12,%r15
jmp    1193 <plugin_api_infolist_hook_cb+0x53>
mov    %r12,%rdi
call   1050 <infolist_free@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.t_infolist = type { i32 }
define %struct.t_infolist* @plugin_api_infolist_hook_cb(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.t_infolist*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.t_infolist*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %6
%12 = load i8*, i8** %7
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = load i8*, i8** %8
%17 = call i32 @hook_valid(i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %15
store %struct.t_infolist* null, %struct.t_infolist** %5
br label %36
20: ; preds = %15, %4
%21 = call %struct.t_infolist* @infolist_new(i32* null)
store %struct.t_infolist* %21, %struct.t_infolist** %10
%22 = load %struct.t_infolist*, %struct.t_infolist** %10
%23 = icmp ne %struct.t_infolist* %22, null
br i1 %23, label %25, label %24
24: ; preds = %20
store %struct.t_infolist* null, %struct.t_infolist** %5
br label %36
25: ; preds = %20
%26 = load %struct.t_infolist*, %struct.t_infolist** %10
%27 = load i8*, i8** %8
%28 = load i8*, i8** %9
%29 = call i32 @hook_add_to_infolist(%struct.t_infolist* %26, i8* %27, i8* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %25
%32 = load %struct.t_infolist*, %struct.t_infolist** %10
%33 = call i32 @infolist_free(%struct.t_infolist* %32)
store %struct.t_infolist* null, %struct.t_infolist** %5
br label %36
34: ; preds = %25
%35 = load %struct.t_infolist*, %struct.t_infolist** %10
store %struct.t_infolist* %35, %struct.t_infolist** %5
br label %36
36: ; preds = %34, %31, %24, %19
%37 = load %struct.t_infolist*, %struct.t_infolist** %5
ret %struct.t_infolist* %37
}

LLVM IR (-O2):
%struct.t_infolist = type { i32 }
define %struct.t_infolist* @plugin_api_infolist_hook_cb(i8* nocapture readnone %0, i8* nocapture readnone %1, i8* %2, i8* %3) {
%5 = icmp eq i8* %2, null
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = tail call i32 @hook_valid(i8* %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6, %4
%10 = tail call %struct.t_infolist* @infolist_new(i32* null)
%11 = icmp eq %struct.t_infolist* %10, null
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = tail call i32 @hook_add_to_infolist(%struct.t_infolist* %10, i8* %2, i8* %3)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @infolist_free(%struct.t_infolist* %10)
br label %17
17: ; preds = %12, %9, %6, %15
%18 = phi %struct.t_infolist* [ null, %15 ], [ null, %6 ], [ null, %9 ], [ %10, %12 ]
ret %struct.t_infolist* %18
}