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

/* Variables and functions */
struct pevent *pevent_alloc();
int /*<<< orphan*/ pevent_free(struct pevent *);
scalar_t__ tracecmd_fill_local_events(char const *, struct pevent *);
struct pevent *tracecmd_local_events(const char *tracing_dir) {
  struct pevent *pevent = NULL;
  pevent = pevent_alloc();
  if (!pevent)
    return NULL;
  if (tracecmd_fill_local_events(tracing_dir, pevent)) {
    pevent_free(pevent);
    pevent = NULL;
  }
  return pevent;
}


x86 assembly (clang, -O0):
<tracecmd_local_events>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <pevent_alloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1167 <tracecmd_local_events+0x37>
movq   $0x0,-0x8(%rbp)
jmp    1197 <tracecmd_local_events+0x67>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <tracecmd_fill_local_events@plt>
cmp    $0x0,%rax
je     118f <tracecmd_local_events+0x5f>
mov    -0x18(%rbp),%rdi
call   1030 <pevent_free@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tracecmd_local_events>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1040 <pevent_alloc@plt>
test   %rax,%rax
je     115e <tracecmd_local_events+0x2e>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1050 <tracecmd_fill_local_events@plt>
test   %rax,%rax
je     1160 <tracecmd_local_events+0x30>
mov    %rbx,%rdi
call   1030 <pevent_free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.pevent = type { i32 }
define %struct.pevent* @tracecmd_local_events(i8* %0) {
%2 = alloca %struct.pevent*
%3 = alloca i8*
%4 = alloca %struct.pevent*
store i8* %0, i8** %3
store %struct.pevent* null, %struct.pevent** %4
%5 = call %struct.pevent* (...) @pevent_alloc()
store %struct.pevent* %5, %struct.pevent** %4
%6 = load %struct.pevent*, %struct.pevent** %4
%7 = icmp ne %struct.pevent* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store %struct.pevent* null, %struct.pevent** %2
br label %19
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load %struct.pevent*, %struct.pevent** %4
%12 = call i64 @tracecmd_fill_local_events(i8* %10, %struct.pevent* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load %struct.pevent*, %struct.pevent** %4
%16 = call i32 @pevent_free(%struct.pevent* %15)
store %struct.pevent* null, %struct.pevent** %4
br label %17
17: ; preds = %14, %9
%18 = load %struct.pevent*, %struct.pevent** %4
store %struct.pevent* %18, %struct.pevent** %2
br label %19
19: ; preds = %17, %8
%20 = load %struct.pevent*, %struct.pevent** %2
ret %struct.pevent* %20
}

LLVM IR (-O2):
%struct.pevent = type { i32 }
define %struct.pevent* @tracecmd_local_events(i8* %0) {
%2 = tail call %struct.pevent* (...) @pevent_alloc()
%3 = icmp eq %struct.pevent* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i64 @tracecmd_fill_local_events(i8* %0, %struct.pevent* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @pevent_free(%struct.pevent* %2)
br label %9
9: ; preds = %4, %7, %1
%10 = phi %struct.pevent* [ null, %1 ], [ null, %7 ], [ %2, %4 ]
ret %struct.pevent* %10
}