#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 *find_and_peek_event(struct tracecmd_input *, unsigned long long,
                                   int *);
struct record *tracecmd_read_data(struct tracecmd_input *, int);
struct record *find_and_read_event(struct tracecmd_input *handle,
                                   unsigned long long offset, int *pcpu) {
  struct record *record;
  int cpu;
  record = find_and_peek_event(handle, offset, &cpu);
  if (record) {
    record = tracecmd_read_data(handle, cpu);
    if (pcpu)
      *pcpu = cpu;
  }
  return record;
}


x86 assembly (clang, -O0):
<find_and_read_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <find_and_peek_event@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117d <find_and_read_event+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <tracecmd_read_data@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1178 <find_and_read_event+0x58>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    117d <find_and_read_event+0x5d>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_and_read_event>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
lea    0x4(%rsp),%rdx
call   1040 <find_and_peek_event@plt>
test   %rax,%rax
je     1153 <find_and_read_event+0x33>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1030 <tracecmd_read_data@plt>
test   %r14,%r14
je     1155 <find_and_read_event+0x35>
mov    0x4(%rsp),%ecx
mov    %ecx,(%r14)
jmp    1155 <find_and_read_event+0x35>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.record = type { i32 }
%struct.tracecmd_input = type { i32 }
define %struct.record* @find_and_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*
%8 = alloca i32
store %struct.tracecmd_input* %0, %struct.tracecmd_input** %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%9 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%10 = load i64, i64* %5
%11 = call %struct.record* @find_and_peek_event(%struct.tracecmd_input* %9, i64 %10, i32* %8)
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 %24
14: ; preds = %3
%15 = load %struct.tracecmd_input*, %struct.tracecmd_input** %4
%16 = load i32, i32* %8
%17 = call %struct.record* @tracecmd_read_data(%struct.tracecmd_input* %15, i32 %16)
store %struct.record* %17, %struct.record** %7
%18 = load i32*, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* %8
%22 = load i32*, i32** %6
store i32 %21, i32* %22
br label %23
23: ; preds = %20, %14
br label %24
24: ; preds = %23, %3
%25 = load %struct.record*, %struct.record** %7
ret %struct.record* %25
}

LLVM IR (-O2):
%struct.record = type { i32 }
%struct.tracecmd_input = type { i32 }
define %struct.record* @find_and_read_event(%struct.tracecmd_input* %0, i64 %1, i32* writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = call %struct.record* @find_and_peek_event(%struct.tracecmd_input* %0, i64 %1, i32* %4)
%7 = icmp eq %struct.record* %6, null
br i1 %7, label %14, label %8
8: ; preds = %3
%9 = load i32, i32* %4
%10 = call %struct.record* @tracecmd_read_data(%struct.tracecmd_input* %0, i32 %9)
%11 = icmp eq i32* %2, null
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = load i32, i32* %4
store i32 %13, i32* %2
br label %14
14: ; preds = %8, %12, %3
%15 = phi %struct.record* [ %10, %12 ], [ %10, %8 ], [ null, %3 ]
ret %struct.record* %15
}