#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 tracecmd_input {
  int dummy;
};
struct record {
  int dummy;
};

/* Variables and functions */
struct record *peek_event(struct tracecmd_input *, unsigned long long, int);
struct record *tracecmd_read_data(struct tracecmd_input *, int);
struct record *read_event(struct tracecmd_input *handle,
                          unsigned long long offset, int cpu) {
  struct record *record;
  record = peek_event(handle, offset, cpu);
  if (record)
    record = tracecmd_read_data(handle, cpu);
  return record;
}


x86 assembly (clang, -O0):
<read_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <peek_event@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1162 <read_event+0x42>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <tracecmd_read_data@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_event>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
call   1040 <peek_event@plt>
test   %rax,%rax
je     1142 <read_event+0x22>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <tracecmd_read_data@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.record = type { i32 }
%struct.tracecmd_input = type { i32 }
define %struct.record* @read_event(%struct.tracecmd_input* %0, i64 %1, i32 %2) {
%4 = tail call %struct.record* @peek_event(%struct.tracecmd_input* %0, i64 %1, i32 %2)
%5 = icmp eq %struct.record* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call %struct.record* @tracecmd_read_data(%struct.tracecmd_input* %0, i32 %2)
br label %8
8: ; preds = %6, %3
%9 = phi %struct.record* [ %7, %6 ], [ null, %3 ]
ret %struct.record* %9
}