#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 btp_thread {
  int dummy;
};
struct btp_backtrace {
  int dummy;
};

/* Variables and functions */
struct btp_thread *btp_backtrace_get_optimized_thread(struct btp_backtrace *,
                                                      int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
struct btp_thread *get_optimized_thread(struct btp_backtrace *backtrace,
                                        int max_frames) {
  struct btp_thread *thread =
      btp_backtrace_get_optimized_thread(backtrace, max_frames);
  if (!thread) {
    fprintf(stderr, "Failed to find the crash thread.\n");
    exit(1);
  }
  return thread;
}


x86 assembly (clang, -O0):
<get_optimized_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <btp_backtrace_get_optimized_thread@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1179 <get_optimized_thread+0x49>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_optimized_thread>:
push   %rax
call   1040 <btp_backtrace_get_optimized_thread@plt>
test   %rax,%rax
je     113d <get_optimized_thread+0xd>
pop    %rcx
ret
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
lea    0xeb3(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.btp_thread = type { i32 }
%struct.btp_backtrace = type { i32 }
@stderr = global i32 0
@.str = [34 x i8] c"Failed to find the crash thread.\0A\00"
define %struct.btp_thread* @get_optimized_thread(%struct.btp_backtrace* %0, i32 %1) {
%3 = alloca %struct.btp_backtrace*
%4 = alloca i32
%5 = alloca %struct.btp_thread*
store %struct.btp_backtrace* %0, %struct.btp_backtrace** %3
store i32 %1, i32* %4
%6 = load %struct.btp_backtrace*, %struct.btp_backtrace** %3
%7 = load i32, i32* %4
%8 = call %struct.btp_thread* @btp_backtrace_get_optimized_thread(%struct.btp_backtrace* %6, i32 %7)
store %struct.btp_thread* %8, %struct.btp_thread** %5
%9 = load %struct.btp_thread*, %struct.btp_thread** %5
%10 = icmp ne %struct.btp_thread* %9, null
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load %struct.btp_thread*, %struct.btp_thread** %5
ret %struct.btp_thread* %16
}

LLVM IR (-O2):
%struct.btp_thread = type { i32 }
%struct.btp_backtrace = type { i32 }
@stderr = global i32 0
@.str = [34 x i8] c"Failed to find the crash thread.\0A\00"
define %struct.btp_thread* @get_optimized_thread(%struct.btp_backtrace* %0, i32 %1) {
%3 = tail call %struct.btp_thread* @btp_backtrace_get_optimized_thread(%struct.btp_backtrace* %0, i32 %1)
%4 = icmp eq %struct.btp_thread* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
ret %struct.btp_thread* %3
}