#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ ss_sp;
  int ss_size;
  scalar_t__ ss_flags;
};
typedef TYPE_1__ stack_t;

/* Variables and functions */
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int sigaltstack(TYPE_1__ *, int /*<<< orphan*/ *);
void *setup_altstack(void) {
  stack_t ss;
  ss.ss_sp = malloc(20 * 1024);
  if (ss.ss_sp == 0) {
    return NULL;
  }
  ss.ss_size = 20 * 1024;
  ss.ss_flags = 0;
  if (sigaltstack(&ss, NULL) == -1) {
    perror("sigaltstack");
    return NULL;
  }
  return ss.ss_sp;
}


x86 assembly (clang, -O0):
<setup_altstack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x5000,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115e <setup_altstack+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <setup_altstack+0x74>
movl   $0x5000,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <sigaltstack@plt>
cmp    $0xffffffff,%eax
jne    119c <setup_altstack+0x6c>
lea    0xe76(%rip),%rdi
call   1040 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <setup_altstack+0x74>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_altstack>:
sub    $0x18,%rsp
mov    $0x5000,%edi
call   1030 <malloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     117c <setup_altstack+0x4c>
movl   $0x5000,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <sigaltstack@plt>
cmp    $0xffffffff,%eax
je     1170 <setup_altstack+0x40>
mov    (%rsp),%rax
add    $0x18,%rsp
ret
lea    0xe89(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i32, i64 }
@.str = [12 x i8] c"sigaltstack\00"
define i8* @setup_altstack() {
%1 = alloca i8*
%2 = alloca %struct.TYPE_3__
%3 = call i64 @malloc(i32 20480)
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
store i64 %3, i64* %4
%5 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
%6 = load i64, i64* %5
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i8* null, i8** %1
br label %20
9: ; preds = %0
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 1
store i32 20480, i32* %10
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 2
store i64 0, i64* %11
%12 = call i32 @sigaltstack(%struct.TYPE_3__* %2, i32* null)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %1
br label %20
16: ; preds = %9
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i32 0, i32 0
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %1
br label %20
20: ; preds = %16, %14, %8
%21 = load i8*, i8** %1
ret i8* %21
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i32, i64 }
@.str = [12 x i8] c"sigaltstack\00"
define i8* @setup_altstack() {
%1 = alloca %struct.TYPE_3__
%2 = bitcast %struct.TYPE_3__* %1 to i8*
%3 = tail call i64 @malloc(i32 20480)
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
store i64 %3, i64* %4
%5 = icmp eq i64 %3, 0
br i1 %5, label %16, label %6
6: ; preds = %0
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
store i32 20480, i32* %7
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 2
store i64 0, i64* %8
%9 = call i32 @sigaltstack(%struct.TYPE_3__* %1, i32* null)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %16
13: ; preds = %6
%14 = load i64, i64* %4
%15 = inttoptr i64 %14 to i8*
br label %16
16: ; preds = %0, %13, %11
%17 = phi i8* [ null, %11 ], [ %15, %13 ], [ null, %0 ]
ret i8* %17
}