#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 */
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int errno;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, void *, ...);
int pthread_attr_destroy(int /*<<< orphan*/ *);
int pthread_attr_getstack(int /*<<< orphan*/ *, void **, size_t *);
int pthread_getattr_np(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_self();
scalar_t__ strlen(void *);
void *thread_t1(void *arg) {
  int ret = 0;
  size_t size = 0;
  void *stack = NULL;
  pthread_attr_t attr;
  printf("%s\n", (char *)arg);
  ret = pthread_getattr_np(pthread_self(), &attr);
  if (ret)
    do {
      errno = ret;
      perror("Get thread attribute failed");
    } while (0);
  ret = pthread_attr_getstack(&attr, &stack, &size);
  if (ret)
    do {
      errno = ret;
      perror("Get stack failed");
    } while (0);
  printf("stack: %p size: %zu\n", stack, size);
  ret = pthread_attr_destroy(&attr);
  if (ret)
    do {
      errno = ret;
      perror("Thread attribute destroy failed");
    } while (0);
  return (void *)strlen(arg);
}


x86 assembly (clang, -O0):
<thread_t1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <pthread_self@plt>
mov    %eax,%edi
lea    -0x24(%rbp),%rsi
call   1030 <pthread_getattr_np@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11e6 <thread_t1+0x76>
jmp    11c9 <thread_t1+0x59>
mov    -0xc(%rbp),%ecx
mov    0x2e0d(%rip),%rax
mov    %ecx,(%rax)
lea    0xe28(%rip),%rdi
call   1080 <perror@plt>
jmp    11e6 <thread_t1+0x76>
lea    -0x24(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <pthread_attr_getstack@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1226 <thread_t1+0xb6>
jmp    1209 <thread_t1+0x99>
mov    -0xc(%rbp),%ecx
mov    0x2dcd(%rip),%rax
mov    %ecx,(%rax)
lea    0xe04(%rip),%rdi
call   1080 <perror@plt>
jmp    1226 <thread_t1+0xb6>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x24(%rbp),%rdi
call   1090 <pthread_attr_destroy@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1274 <thread_t1+0x104>
jmp    1257 <thread_t1+0xe7>
mov    -0xc(%rbp),%ecx
mov    0x2d7f(%rip),%rax
mov    %ecx,(%rax)
lea    0xddc(%rip),%rdi
call   1080 <perror@plt>
jmp    1274 <thread_t1+0x104>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_t1>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe6f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <pthread_self@plt>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
call   1030 <pthread_getattr_np@plt>
test   %eax,%eax
jne    11fe <thread_t1+0x8e>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x18(%rsp),%rdx
call   1060 <pthread_attr_getstack@plt>
test   %eax,%eax
jne    1215 <thread_t1+0xa5>
mov    0x10(%rsp),%rsi
mov    0x18(%rsp),%rdx
lea    0xe56(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rdi
call   1090 <pthread_attr_destroy@plt>
test   %eax,%eax
jne    122c <thread_t1+0xbc>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2ddb(%rip),%rcx
mov    %eax,(%rcx)
lea    0xdf6(%rip),%rdi
call   1080 <perror@plt>
jmp    11b2 <thread_t1+0x42>
mov    0x2dc4(%rip),%rcx
mov    %eax,(%rcx)
lea    0xdfb(%rip),%rdi
call   1080 <perror@plt>
jmp    11ca <thread_t1+0x5a>
mov    0x2dad(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe0a(%rip),%rdi
call   1080 <perror@plt>
jmp    11f0 <thread_t1+0x80>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"Get thread attribute failed\00"
@.str.2 = [17 x i8] c"Get stack failed\00"
@.str.3 = [21 x i8] c"stack: %p size: %zu\0A\00"
@.str.4 = [32 x i8] c"Thread attribute destroy failed\00"
define i8* @thread_t1(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i64 0, i64* %4
store i8* null, i8** %5
%7 = load i8*, i8** %2
%8 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = call i32 (...) @pthread_self()
%10 = call i32 @pthread_getattr_np(i32 %9, i32* %6)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %1
br label %14
14: ; preds = %13
%15 = load i32, i32* %3
store i32 %15, i32* @errno
%16 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %14
br label %18
18: ; preds = %17, %1
%19 = call i32 @pthread_attr_getstack(i32* %6, i8** %5, i64* %4)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18
br label %23
23: ; preds = %22
%24 = load i32, i32* %3
store i32 %24, i32* @errno
%25 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %23
br label %27
27: ; preds = %26, %18
%28 = load i8*, i8** %5
%29 = load i64, i64* %4
%30 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %28, i64 %29)
%31 = call i32 @pthread_attr_destroy(i32* %6)
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %27
br label %35
35: ; preds = %34
%36 = load i32, i32* %3
store i32 %36, i32* @errno
%37 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %35
br label %39
39: ; preds = %38, %27
%40 = load i8*, i8** %2
%41 = call i64 @strlen(i8* %40)
%42 = inttoptr i64 %41 to i8*
ret i8* %42
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"Get thread attribute failed\00"
@.str.2 = [17 x i8] c"Get stack failed\00"
@.str.3 = [21 x i8] c"stack: %p size: %zu\0A\00"
@.str.4 = [32 x i8] c"Thread attribute destroy failed\00"
define i8* @thread_t1(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i32* %4 to i8*
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32 (...) @pthread_self()
%10 = call i32 @pthread_getattr_np(i32 %9, i32* %4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %1
store i32 %10, i32* @errno
%13 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = call i32 @pthread_attr_getstack(i32* %4, i8** %3, i64* %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
store i32 %15, i32* @errno
%18 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = load i8*, i8** %3
%21 = load i64, i64* %2
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %20, i64 %21)
%23 = call i32 @pthread_attr_destroy(i32* %4)
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %19
store i32 %23, i32* @errno
%26 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
%28 = call i64 @strlen(i8* dereferenceable(1) %0)
%29 = inttoptr i64 %28 to i8*
ret i8* %29
}