#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_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int ss_flags;
};
struct TYPE_6__ {
  TYPE_1__ uc_stack;
};
typedef TYPE_2__ ucontext_t;

/* Variables and functions */
int SS_ONSTACK;
scalar_t__ getcontext(TYPE_2__ *);
int /*<<< orphan*/ setcontext(TYPE_2__ *);
void sigsegv_reset_onstack_flag(void) {
  ucontext_t uc;
  if (getcontext(&uc) >= 0)
    if (uc.uc_stack.ss_flags & SS_ONSTACK) {
      uc.uc_stack.ss_flags &= ~SS_ONSTACK;
      setcontext(&uc);
    }
}


x86 assembly (clang, -O0):
<sigsegv_reset_onstack_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
call   1040 <getcontext@plt>
cmp    $0x0,%rax
jl     1170 <sigsegv_reset_onstack_flag+0x50>
mov    -0x8(%rbp),%eax
mov    0x2ea3(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     116b <sigsegv_reset_onstack_flag+0x4b>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <setcontext@plt>
jmp    1170 <sigsegv_reset_onstack_flag+0x50>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigsegv_reset_onstack_flag>:
push   %rax
mov    %rsp,%rdi
call   1040 <getcontext@plt>
test   %rax,%rax
js     114d <sigsegv_reset_onstack_flag+0x2d>
mov    (%rsp),%eax
mov    0x2eb0(%rip),%rcx
mov    (%rcx),%ecx
test   %eax,%ecx
je     114d <sigsegv_reset_onstack_flag+0x2d>
not    %ecx
and    %ecx,%eax
mov    %eax,(%rsp)
mov    %rsp,%rdi
call   1030 <setcontext@plt>
pop    %rax
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@SS_ONSTACK = global i32 0
define void @sigsegv_reset_onstack_flag() {
%1 = alloca %struct.TYPE_6__
%2 = call i64 @getcontext(%struct.TYPE_6__* %1)
%3 = icmp sge i64 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %0
%5 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i32 0, i32 0
%6 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = load i32, i32* @SS_ONSTACK
%9 = and i32 %7, %8
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %4
%12 = load i32, i32* @SS_ONSTACK
%13 = xor i32 %12, -1
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i32 0, i32 0
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = and i32 %16, %13
store i32 %17, i32* %15
%18 = call i32 @setcontext(%struct.TYPE_6__* %1)
br label %19
19: ; preds = %11, %4
br label %20
20: ; preds = %19, %0
ret void
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@SS_ONSTACK = global i32 0
define void @sigsegv_reset_onstack_flag() {
%1 = alloca %struct.TYPE_6__
%2 = bitcast %struct.TYPE_6__* %1 to i8*
%3 = call i64 @getcontext(%struct.TYPE_6__* %1)
%4 = icmp sgt i64 %3, -1
br i1 %4, label %5, label %15
5: ; preds = %0
%6 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i64 0, i32 0, i32 0
%7 = load i32, i32* %6
%8 = load i32, i32* @SS_ONSTACK
%9 = and i32 %8, %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %5
%12 = xor i32 %8, -1
%13 = and i32 %7, %12
store i32 %13, i32* %6
%14 = call i32 @setcontext(%struct.TYPE_6__* %1)
br label %15
15: ; preds = %5, %11, %0
ret void
}