#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 trace_seq {
  int dummy;
};
struct tep_record {
  int dummy;
};
struct event_format {
  int dummy;
};

/* Variables and functions */
char *find_exit_reason(unsigned long long, unsigned long long);
scalar_t__ tep_get_field_val(struct trace_seq *, struct event_format *,
                             char const *, struct tep_record *,
                             unsigned long long *, int);
int /*<<< orphan*/ trace_seq_printf(struct trace_seq *, char *, ...);
int print_exit_reason(struct trace_seq *s, struct tep_record *record,
                      struct event_format *event, const char *field) {
  unsigned long long isa;
  unsigned long long val;
  const char *reason;
  if (tep_get_field_val(s, event, field, record, &val, 1) < 0)
    return -1;
  if (tep_get_field_val(s, event, "isa", record, &isa, 0) < 0)
    isa = 1;
  reason = find_exit_reason(isa, val);
  if (reason)
    trace_seq_printf(s, "reason %s", reason);
  else
    trace_seq_printf(s, "reason UNKNOWN (%llu)", val);
  return 0;
}


x86 assembly (clang, -O0):
<print_exit_reason>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x38(%rbp),%r8
mov    $0x1,%r9d
call   1050 <tep_get_field_val@plt>
cmp    $0x0,%rax
jge    117d <print_exit_reason+0x4d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1202 <print_exit_reason+0xd2>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe70(%rip),%rdx
lea    -0x30(%rbp),%r8
xor    %r9d,%r9d
call   1050 <tep_get_field_val@plt>
cmp    $0x0,%rax
jge    11ae <print_exit_reason+0x7e>
movq   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <find_exit_reason@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     11e5 <print_exit_reason+0xb5>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1040 <trace_seq_printf@plt>
jmp    11fb <print_exit_reason+0xcb>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1040 <trace_seq_printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_exit_reason>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%r8
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r15,%rcx
mov    $0x1,%r9d
call   1050 <tep_get_field_val@plt>
test   %rax,%rax
js     1187 <print_exit_reason+0x57>
lea    0xe9b(%rip),%rdx
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
xor    %r9d,%r9d
call   1050 <tep_get_field_val@plt>
test   %rax,%rax
js     118e <print_exit_reason+0x5e>
mov    0x8(%rsp),%rdi
jmp    119c <print_exit_reason+0x6c>
mov    $0xffffffff,%ebx
jmp    11d2 <print_exit_reason+0xa2>
movq   $0x1,0x8(%rsp)
mov    $0x1,%edi
mov    (%rsp),%rsi
call   1030 <find_exit_reason@plt>
test   %rax,%rax
je     11bb <print_exit_reason+0x8b>
lea    0xe53(%rip),%rsi
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %rax,%rdx
jmp    11cb <print_exit_reason+0x9b>
mov    (%rsp),%rdx
lea    0xe48(%rip),%rsi
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <trace_seq_printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.trace_seq = type { i32 }
%struct.tep_record = type { i32 }
%struct.event_format = type { i32 }
@.str = [4 x i8] c"isa\00"
@.str.1 = [10 x i8] c"reason %s\00"
@.str.2 = [22 x i8] c"reason UNKNOWN (%llu)\00"
define i32 @print_exit_reason(%struct.trace_seq* %0, %struct.tep_record* %1, %struct.event_format* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.trace_seq*
%7 = alloca %struct.tep_record*
%8 = alloca %struct.event_format*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
store %struct.trace_seq* %0, %struct.trace_seq** %6
store %struct.tep_record* %1, %struct.tep_record** %7
store %struct.event_format* %2, %struct.event_format** %8
store i8* %3, i8** %9
%13 = load %struct.trace_seq*, %struct.trace_seq** %6
%14 = load %struct.event_format*, %struct.event_format** %8
%15 = load i8*, i8** %9
%16 = load %struct.tep_record*, %struct.tep_record** %7
%17 = call i64 @tep_get_field_val(%struct.trace_seq* %13, %struct.event_format* %14, i8* %15, %struct.tep_record* %16, i64* %11, i32 1)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 -1, i32* %5
br label %42
20: ; preds = %4
%21 = load %struct.trace_seq*, %struct.trace_seq** %6
%22 = load %struct.event_format*, %struct.event_format** %8
%23 = load %struct.tep_record*, %struct.tep_record** %7
%24 = call i64 @tep_get_field_val(%struct.trace_seq* %21, %struct.event_format* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.tep_record* %23, i64* %10, i32 0)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i64 1, i64* %10
br label %27
27: ; preds = %26, %20
%28 = load i64, i64* %10
%29 = load i64, i64* %11
%30 = call i8* @find_exit_reason(i64 %28, i64 %29)
store i8* %30, i8** %12
%31 = load i8*, i8** %12
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %27
%34 = load %struct.trace_seq*, %struct.trace_seq** %6
%35 = load i8*, i8** %12
%36 = call i32 (%struct.trace_seq*, i8*, ...) @trace_seq_printf(%struct.trace_seq* %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %41
37: ; preds = %27
%38 = load %struct.trace_seq*, %struct.trace_seq** %6
%39 = load i64, i64* %11
%40 = call i32 (%struct.trace_seq*, i8*, ...) @trace_seq_printf(%struct.trace_seq* %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %39)
br label %41
41: ; preds = %37, %33
store i32 0, i32* %5
br label %42
42: ; preds = %41, %19
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
%struct.trace_seq = type { i32 }
%struct.tep_record = type { i32 }
%struct.event_format = type { i32 }
@.str = [4 x i8] c"isa\00"
@.str.1 = [10 x i8] c"reason %s\00"
@.str.2 = [22 x i8] c"reason UNKNOWN (%llu)\00"
define i32 @print_exit_reason(%struct.trace_seq* %0, %struct.tep_record* %1, %struct.event_format* %2, i8* %3) {
%5 = alloca i64
%6 = alloca i64
%7 = bitcast i64* %5 to i8*
%8 = bitcast i64* %6 to i8*
%9 = call i64 @tep_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* %3, %struct.tep_record* %1, i64* %6, i32 1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %27, label %11
11: ; preds = %4
%12 = call i64 @tep_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.tep_record* %1, i64* %5, i32 0)
%13 = icmp slt i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = load i64, i64* %5
br label %17
16: ; preds = %11
store i64 1, i64* %5
br label %17
17: ; preds = %14, %16
%18 = phi i64 [ %15, %14 ], [ 1, %16 ]
%19 = load i64, i64* %6
%20 = call i8* @find_exit_reason(i64 %18, i64 %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = call i32 (%struct.trace_seq*, i8*, ...) @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %27
24: ; preds = %17
%25 = load i64, i64* %6
%26 = call i32 (%struct.trace_seq*, i8*, ...) @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %25)
br label %27
27: ; preds = %22, %24, %4
%28 = phi i32 [ -1, %4 ], [ 0, %24 ], [ 0, %22 ]
ret i32 %28
}