#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*/ 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 *start_thread(void *argv) {
  printf("============begin start thread=============\n");
  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");
  return 0;
}


x86 assembly (clang, -O0):
<start_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
call   1050 <printf@plt>
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     11c2 <start_thread+0x62>
jmp    119c <start_thread+0x3c>
mov    -0xc(%rbp),%ecx
mov    0x2e3a(%rip),%rax
mov    %ecx,(%rax)
lea    0xe7e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe77(%rip),%rdi
call   1050 <printf@plt>
lea    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <display_pthread_attr@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_thread>:
push   %rax
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
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    11a5 <start_thread+0x45>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7c(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <display_pthread_attr@plt>
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e34(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe4b(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

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

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