#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ ti_state;
};
typedef TYPE_1__ td_thrinfo_t;
typedef int /*<<< orphan*/ td_thrhandle_t;
typedef scalar_t__ td_err_e;

/* Variables and functions */
scalar_t__ TD_OK;
scalar_t__ TD_THR_UNKNOWN;
scalar_t__ TD_THR_ZOMBIE;
int /*<<< orphan*/ error(char *, int /*<<< orphan*/);
int /*<<< orphan*/ maybe_attach_thread(int /*<<< orphan*/ const *, TYPE_1__ *);
scalar_t__ td_thr_get_info(int /*<<< orphan*/ const *, TYPE_1__ *);
int /*<<< orphan*/ thread_db_err_str(scalar_t__);
int find_new_threads_callback(const td_thrhandle_t *th_p, void *data) {
  td_thrinfo_t ti;
  td_err_e err;
  err = td_thr_get_info(th_p, &ti);
  if (err != TD_OK)
    error("Cannot get thread info: %s", thread_db_err_str(err));
  if (ti.ti_state == TD_THR_UNKNOWN || ti.ti_state == TD_THR_ZOMBIE)
    return 0;
  maybe_attach_thread(th_p, &ti);
  return 0;
}


x86 assembly (clang, -O0):
<find_new_threads_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <td_thr_get_info@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
je     118c <find_new_threads_callback+0x4c>
mov    -0x28(%rbp),%rdi
call   1030 <thread_db_err_str@plt>
mov    %eax,%esi
lea    0xe79(%rip),%rdi
call   1050 <error@plt>
mov    -0x20(%rbp),%rax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
je     11b4 <find_new_threads_callback+0x74>
mov    -0x20(%rbp),%rax
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%rax
jne    11c0 <find_new_threads_callback+0x80>
movl   $0x0,-0x4(%rbp)
jmp    11d4 <find_new_threads_callback+0x94>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <maybe_attach_thread@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_new_threads_callback>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1060 <td_thr_get_info@plt>
mov    0x2e77(%rip),%rcx
cmp    (%rcx),%rax
je     1174 <find_new_threads_callback+0x34>
mov    %rax,%rdi
call   1030 <thread_db_err_str@plt>
lea    0xe93(%rip),%rdi
mov    %eax,%esi
call   1050 <error@plt>
mov    0x8(%rsp),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
je     119e <find_new_threads_callback+0x5e>
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
je     119e <find_new_threads_callback+0x5e>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <maybe_attach_thread@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64 }
@TD_OK = global i64 0
@.str = [27 x i8] c"Cannot get thread info: %s\00"
@TD_THR_UNKNOWN = global i64 0
@TD_THR_ZOMBIE = global i64 0
define i32 @find_new_threads_callback(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca %struct.TYPE_4__
%7 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = load i32*, i32** %4
%9 = call i64 @td_thr_get_info(i32* %8, %struct.TYPE_4__* %6)
store i64 %9, i64* %7
%10 = load i64, i64* %7
%11 = load i64, i64* @TD_OK
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i64, i64* %7
%15 = call i32 @thread_db_err_str(i64 %14)
%16 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %2
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%19 = load i64, i64* %18
%20 = load i64, i64* @TD_THR_UNKNOWN
%21 = icmp eq i64 %19, %20
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%24 = load i64, i64* %23
%25 = load i64, i64* @TD_THR_ZOMBIE
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %22, %17
store i32 0, i32* %3
br label %31
28: ; preds = %22
%29 = load i32*, i32** %4
%30 = call i32 @maybe_attach_thread(i32* %29, %struct.TYPE_4__* %6)
store i32 0, i32* %3
br label %31
31: ; preds = %28, %27
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64 }
@TD_OK = global i64 0
@.str = [27 x i8] c"Cannot get thread info: %s\00"
@TD_THR_UNKNOWN = global i64 0
@TD_THR_ZOMBIE = global i64 0
define i32 @find_new_threads_callback(i32* %0, i8* nocapture readnone %1) {
%3 = alloca %struct.TYPE_4__
%4 = bitcast %struct.TYPE_4__* %3 to i8*
%5 = call i64 @td_thr_get_info(i32* %0, %struct.TYPE_4__* %3)
%6 = load i64, i64* @TD_OK
%7 = icmp eq i64 %5, %6
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i32 @thread_db_err_str(i64 %5)
%10 = call i32 @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %2
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%13 = load i64, i64* %12
%14 = load i64, i64* @TD_THR_UNKNOWN
%15 = icmp eq i64 %13, %14
%16 = load i64, i64* @TD_THR_ZOMBIE
%17 = icmp eq i64 %13, %16
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %21, label %19
19: ; preds = %11
%20 = call i32 @maybe_attach_thread(i32* %0, %struct.TYPE_4__* %3)
br label %21
21: ; preds = %11, %19
ret i32 0
}