#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*/ ucontext_t;

/* Variables and functions */
int __fillcontextx(char *);
int /*<<< orphan*/ __getcontextx_size();
int errno;
int /*<<< orphan*/ free(char *);
char *malloc(int /*<<< orphan*/);
ucontext_t *__getcontextx(void) {
  char *ctx;
  int error;
  ctx = malloc(__getcontextx_size());
  if (ctx == NULL)
    return (NULL);
  if (__fillcontextx(ctx) == -1) {
    error = errno;
    free(ctx);
    errno = error;
    return (NULL);
  }
  return ((ucontext_t *)ctx);
}


x86 assembly (clang, -O0):
<__getcontextx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <__getcontextx_size@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1172 <__getcontextx+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11ba <__getcontextx+0x7a>
mov    -0x10(%rbp),%rdi
call   1040 <__fillcontextx@plt>
cmp    $0xffffffff,%eax
jne    11b2 <__getcontextx+0x72>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%ecx
mov    0x2e3d(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11ba <__getcontextx+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__getcontextx>:
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <__getcontextx_size@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     117a <__getcontextx+0x3a>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <__fillcontextx@plt>
cmp    $0xffffffff,%eax
je     116f <__getcontextx+0x2f>
mov    %rbx,%r14
jmp    117a <__getcontextx+0x3a>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i32 0
define i32* @__getcontextx() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i32
%4 = call i32 (...) @__getcontextx_size()
%5 = call i8* @malloc(i32 %4)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
store i32* null, i32** %1
br label %21
9: ; preds = %0
%10 = load i8*, i8** %2
%11 = call i32 @__fillcontextx(i8* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* @errno
store i32 %14, i32* %3
%15 = load i8*, i8** %2
%16 = call i32 @free(i8* %15)
%17 = load i32, i32* %3
store i32 %17, i32* @errno
store i32* null, i32** %1
br label %21
18: ; preds = %9
%19 = load i8*, i8** %2
%20 = bitcast i8* %19 to i32*
store i32* %20, i32** %1
br label %21
21: ; preds = %18, %13, %8
%22 = load i32*, i32** %1
ret i32* %22
}

LLVM IR (-O2):
@errno = global i32 0
define i32* @__getcontextx() {
%1 = tail call i32 (...) @__getcontextx_size()
%2 = tail call i8* @malloc(i32 %1)
%3 = icmp eq i8* %2, null
br i1 %3, label %11, label %4
4: ; preds = %0
%5 = tail call i32 @__fillcontextx(i8* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @free(i8* %2)
br label %11
9: ; preds = %4
%10 = bitcast i8* %2 to i32*
br label %11
11: ; preds = %0, %9, %7
%12 = phi i32* [ null, %7 ], [ %10, %9 ], [ null, %0 ]
ret i32* %12
}