#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 */
struct sched_param {
  int dummy;
};
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int PTHREAD_CREATE_DETACHED;
int PTHREAD_CREATE_JOINABLE;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int pthread_attr_getdetachstate(int /*<<< orphan*/ *, int *);
int pthread_attr_getstack(int /*<<< orphan*/ *, void **, size_t *);
void display_pthread_attr(pthread_attr_t *attr, char *prefix) {
  int s, i;
  size_t v;
  void *stkaddr;
  struct sched_param sp;
  s = pthread_attr_getdetachstate(attr, &i);
  if (s != 0)
    do {
      errno = s;
      perror("pthread_attr_getdetachstate");
      exit(EXIT_FAILURE);
    } while (0);
  printf("%sDetach state        = %s\n", prefix,
         (i == PTHREAD_CREATE_DETACHED)   ? "PTHREAD_CREATE_DETACHED"
         : (i == PTHREAD_CREATE_JOINABLE) ? "PTHREAD_CREATE_JOINABLE"
                                          : "???");
  s = pthread_attr_getstack(attr, &stkaddr, &v);
  if (s != 0)
    do {
      errno = s;
      perror("pthread_attr_getstack");
      exit(EXIT_FAILURE);
    } while (0);
  printf("%sStack address       = %p\n", prefix, stkaddr);
  printf("%sStack size          = 0x%x bytes\n", prefix, (unsigned)v);
}


x86 assembly (clang, -O0):
<display_pthread_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <pthread_attr_getdetachstate@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a5 <display_pthread_attr+0x55>
jmp    117f <display_pthread_attr+0x2f>
mov    -0x14(%rbp),%ecx
mov    0x2e47(%rip),%rax
mov    %ecx,(%rax)
lea    0xe6e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%eax
jne    11cf <display_pthread_attr+0x7f>
lea    0xe72(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11f3 <display_pthread_attr+0xa3>
mov    -0x18(%rbp),%edx
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rax
lea    0xe67(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <pthread_attr_getstack@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1252 <display_pthread_attr+0x102>
jmp    122c <display_pthread_attr+0xdc>
mov    -0x14(%rbp),%ecx
mov    0x2d9a(%rip),%rax
mov    %ecx,(%rax)
lea    0xe2d(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    %eax,%edx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_pthread_attr>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x4(%rsp),%rsi
call   1070 <pthread_attr_getdetachstate@plt>
test   %eax,%eax
jne    11fc <display_pthread_attr+0xac>
mov    0x4(%rsp),%eax
mov    0x2e5e(%rip),%rcx
mov    0x2e67(%rip),%rdx
cmp    (%rdx),%eax
lea    0xec6(%rip),%rdx
lea    0xed7(%rip),%rsi
cmove  %rdx,%rsi
cmp    (%rcx),%eax
lea    0xe9a(%rip),%rdx
cmovne %rsi,%rdx
lea    0xe73(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <pthread_attr_getstack@plt>
test   %eax,%eax
jne    120e <display_pthread_attr+0xbe>
mov    0x8(%rsp),%rdx
lea    0xead(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%edx
lea    0xeb4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dcd(%rip),%rcx
mov    %eax,(%rcx)
lea    0xdf4(%rip),%rdi
jmp    121e <display_pthread_attr+0xce>
mov    0x2dbb(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sched_param = type { i32 }
@errno = global i32 0
@.str = [28 x i8] c"pthread_attr_getdetachstate\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"%sDetach state = %s\0A\00"
@PTHREAD_CREATE_DETACHED = global i32 0
@.str.2 = [24 x i8] c"PTHREAD_CREATE_DETACHED\00"
@PTHREAD_CREATE_JOINABLE = global i32 0
@.str.3 = [24 x i8] c"PTHREAD_CREATE_JOINABLE\00"
@.str.4 = [4 x i8] c"???\00"
@.str.5 = [22 x i8] c"pthread_attr_getstack\00"
@.str.6 = [28 x i8] c"%sStack address = %p\0A\00"
@.str.7 = [36 x i8] c"%sStack size = 0x%x bytes\0A\00"
define void @display_pthread_attr(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca %struct.sched_param
store i32* %0, i32** %3
store i8* %1, i8** %4
%10 = load i32*, i32** %3
%11 = call i32 @pthread_attr_getdetachstate(i32* %10, i32* %6)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %2
br label %15
15: ; preds = %14
%16 = load i32, i32* %5
store i32 %16, i32* @errno
%17 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; No predecessors!
br label %21
21: ; preds = %20, %2
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = load i32, i32* @PTHREAD_CREATE_DETACHED
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %21
br label %33
27: ; preds = %21
%28 = load i32, i32* %6
%29 = load i32, i32* @PTHREAD_CREATE_JOINABLE
%30 = icmp eq i32 %28, %29
%31 = zext i1 %30 to i64
%32 = select i1 %30, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
br label %33
33: ; preds = %27, %26
%34 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), %26 ], [ %32, %27 ]
%35 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %34)
%36 = load i32*, i32** %3
%37 = call i32 @pthread_attr_getstack(i32* %36, i8** %8, i64* %7)
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %33
br label %41
41: ; preds = %40
%42 = load i32, i32* %5
store i32 %42, i32* @errno
%43 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; No predecessors!
br label %47
47: ; preds = %46, %33
%48 = load i8*, i8** %4
%49 = load i8*, i8** %8
%50 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %48, i8* %49)
%51 = load i8*, i8** %4
%52 = load i64, i64* %7
%53 = trunc i64 %52 to i32
%54 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %51, i32 %53)
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [28 x i8] c"pthread_attr_getdetachstate\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [28 x i8] c"%sDetach state = %s\0A\00"
@PTHREAD_CREATE_DETACHED = global i32 0
@.str.2 = [24 x i8] c"PTHREAD_CREATE_DETACHED\00"
@PTHREAD_CREATE_JOINABLE = global i32 0
@.str.3 = [24 x i8] c"PTHREAD_CREATE_JOINABLE\00"
@.str.4 = [4 x i8] c"???\00"
@.str.5 = [22 x i8] c"pthread_attr_getstack\00"
@.str.6 = [28 x i8] c"%sStack address = %p\0A\00"
@.str.7 = [36 x i8] c"%sStack size = 0x%x bytes\0A\00"
define void @display_pthread_attr(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = bitcast i8** %5 to i8*
%9 = call i32 @pthread_attr_getdetachstate(i32* %0, i32* %3)
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
store i32 %9, i32* @errno
%12 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i32, i32* %3
%17 = load i32, i32* @PTHREAD_CREATE_DETACHED
%18 = icmp eq i32 %16, %17
%19 = load i32, i32* @PTHREAD_CREATE_JOINABLE
%20 = icmp eq i32 %16, %19
%21 = select i1 %20, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%22 = select i1 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %21
%23 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %22)
%24 = call i32 @pthread_attr_getstack(i32* %0, i8** %5, i64* %4)
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %15
store i32 %24, i32* @errno
%27 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %15
%31 = load i8*, i8** %5
%32 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %1, i8* %31)
%33 = load i64, i64* %4
%34 = trunc i64 %33 to i32
%35 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0), i8* %1, i32 %34)
ret void
}