#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
char *lksmith_get_thread_name();
int lksmith_set_thread_name(char const *const);
int /*<<< orphan*/ stderr;
int strcmp(char const *const, char const *);
int test_thread_name_set_and_get_impl(void) {
  const char *const MY_THREAD = "my_thread";
  const char *name;
  do {
    int __my_ret__ = lksmith_set_thread_name(MY_THREAD);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 45,
              "lksmith_set_thread_name(MY_THREAD)");
      return __my_ret__;
    }
  } while (0);
  ;
  name = lksmith_get_thread_name();
  do {
    if ((name) == (NULL)) {
      fprintf(stderr, "failed on line %d: %s\n", 47, "name");
      return 1;
    }
  } while (0);
  ;
  do {
    int __my_ret__ = strcmp(MY_THREAD, name);
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 48, "strcmp(MY_THREAD, name)");
      return __my_ret__;
    }
  } while (0);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<test_thread_name_set_and_get_impl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea6(%rip),%rdi
call   1030 <lksmith_set_thread_name@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1198 <test_thread_name_set_and_get_impl+0x58>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
mov    $0x2d,%edx
lea    0xe99(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123f <test_thread_name_set_and_get_impl+0xff>
jmp    119d <test_thread_name_set_and_get_impl+0x5d>
mov    $0x0,%al
call   1060 <lksmith_get_thread_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <test_thread_name_set_and_get_impl+0xa0>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x2f,%edx
lea    0xe75(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123f <test_thread_name_set_and_get_impl+0xff>
jmp    11e5 <test_thread_name_set_and_get_impl+0xa5>
jmp    11ea <test_thread_name_set_and_get_impl+0xaa>
mov    -0x18(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1040 <strcmp@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1233 <test_thread_name_set_and_get_impl+0xf3>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
mov    $0x30,%edx
lea    0xe26(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123f <test_thread_name_set_and_get_impl+0xff>
jmp    1238 <test_thread_name_set_and_get_impl+0xf8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_thread_name_set_and_get_impl>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
call   1030 <lksmith_set_thread_name@plt>
test   %eax,%eax
je     117f <test_thread_name_set_and_get_impl+0x3f>
mov    %eax,%ebx
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
lea    0xeb5(%rip),%rcx
mov    $0x2d,%edx
call   1050 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <lksmith_get_thread_name@plt>
test   %rax,%rax
je     11c7 <test_thread_name_set_and_get_impl+0x87>
lea    0xe6c(%rip),%rdi
mov    %rax,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1176 <test_thread_name_set_and_get_impl+0x36>
mov    %eax,%ebp
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
lea    0xe90(%rip),%rcx
mov    $0x30,%edx
call   1050 <fprintf@plt>
mov    %ebp,%ebx
jmp    1176 <test_thread_name_set_and_get_impl+0x36>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
lea    0xe66(%rip),%rcx
mov    $0x2f,%edx
call   1050 <fprintf@plt>
mov    $0x1,%ebx
jmp    1176 <test_thread_name_set_and_get_impl+0x36>

LLVM IR (-O0):
@.str = [10 x i8] c"my_thread\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [35 x i8] c"lksmith_set_thread_name(MY_THREAD)\00"
@.str.3 = [5 x i8] c"name\00"
@.str.4 = [24 x i8] c"strcmp(MY_THREAD, name)\00"
define i32 @test_thread_name_set_and_get_impl() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
br label %6
6: ; preds = %0
%7 = call i32 @lksmith_set_thread_name(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0))
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 45, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* %4
store i32 %13, i32* %1
br label %36
14: ; preds = %6
br label %15
15: ; preds = %14
%16 = call i8* (...) @lksmith_get_thread_name()
store i8* %16, i8** %3
br label %17
17: ; preds = %15
%18 = load i8*, i8** %3
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %36
23: ; preds = %17
br label %24
24: ; preds = %23
br label %25
25: ; preds = %24
%26 = load i8*, i8** %3
%27 = call i32 @strcmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i8* %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 48, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32, i32* %5
store i32 %33, i32* %1
br label %36
34: ; preds = %25
br label %35
35: ; preds = %34
store i32 0, i32* %1
br label %36
36: ; preds = %35, %30, %20, %10
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [10 x i8] c"my_thread\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [35 x i8] c"lksmith_set_thread_name(MY_THREAD)\00"
@.str.3 = [5 x i8] c"name\00"
@.str.4 = [24 x i8] c"strcmp(MY_THREAD, name)\00"
define i32 @test_thread_name_set_and_get_impl() {
%1 = tail call i32 @lksmith_set_thread_name(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 45, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %18
6: ; preds = %0
%7 = tail call i8* (...) @lksmith_get_thread_name()
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %18
12: ; preds = %6
%13 = tail call i32 @strcmp(i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %7)
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 48, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %15, %12, %3, %9
%19 = phi i32 [ 1, %9 ], [ %1, %3 ], [ 0, %12 ], [ %13, %15 ]
ret i32 %19
}