#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ display_pthread_attr(int /*<<< orphan*/ *, char *);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int pthread_getattr_np(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_self();
void *thread_start(void *arg) {
  int s;
  pthread_attr_t gattr;
  s = pthread_getattr_np(pthread_self(), &gattr);
  if (s != 0)
    do {
      errno = s;
      perror("pthread_getattr_np");
      exit(EXIT_FAILURE);
    } while (0);
  printf("Thread attributes:\n");
  display_pthread_attr(&gattr, "\t");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<thread_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,%edi
lea    -0x10(%rbp),%rsi
call   1030 <pthread_getattr_np@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b6 <thread_start+0x56>
jmp    1190 <thread_start+0x30>
mov    -0xc(%rbp),%ecx
mov    0x2e46(%rip),%rax
mov    %ecx,(%rax)
lea    0xe5d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
lea    -0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <display_pthread_attr@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<thread_start>:
push   %rax
xor    %eax,%eax
call   1060 <pthread_self@plt>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
call   1040 <pthread_getattr_np@plt>
test   %eax,%eax
jne    11a3 <thread_start+0x43>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
lea    0xe88(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <display_pthread_attr@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2e36(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe4d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [19 x i8] c"pthread_getattr_np\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"Thread attributes:\0A\00"
@.str.2 = [2 x i8] c"\09\00"
@EXIT_SUCCESS = global i32 0
define i8* @thread_start(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @pthread_self()
%6 = call i32 @pthread_getattr_np(i32 %5, i32* %4)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
br label %10
10: ; preds = %9
%11 = load i32, i32* %3
store i32 %11, i32* @errno
%12 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; No predecessors!
br label %16
16: ; preds = %15, %1
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @display_pthread_attr(i32* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_SUCCESS
%20 = call i32 @exit(i32 %19)
unreachable
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [19 x i8] c"pthread_getattr_np\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c"\09\00"
@EXIT_SUCCESS = global i32 0
@str = [19 x i8] c"Thread attributes:\00"
define noalias i8* @thread_start(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @pthread_self()
%5 = call i32 @pthread_getattr_np(i32 %4, i32* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
store i32 %5, i32* @errno
%8 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%13 = call i32 @display_pthread_attr(i32* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_SUCCESS
%15 = call i32 @exit(i32 %14)
unreachable
}