#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 sigaction {
  int /*<<< orphan*/ sa_flags;
};

/* Variables and functions */
int /*<<< orphan*/ SA_RESTART;
int sigaction(int, struct sigaction *, struct sigaction *);
int _siginterrupt(int signal, int flag) {
  struct sigaction actbuff;
  if (sigaction(signal, NULL, &actbuff) == -1) {
    return -1;
  }
  if (flag) {
    actbuff.sa_flags &= ~SA_RESTART;
  } else {
    actbuff.sa_flags &= SA_RESTART;
  }
  if (sigaction(signal, &actbuff, NULL) == -1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_siginterrupt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    1143 <_siginterrupt+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <_siginterrupt+0x8f>
cmpl   $0x0,-0xc(%rbp)
je     1164 <_siginterrupt+0x54>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1173 <_siginterrupt+0x63>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
jne    1198 <_siginterrupt+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <_siginterrupt+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_siginterrupt>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rdx
xor    %esi,%esi
call   1030 <sigaction@plt>
cmp    $0xffffffff,%eax
je     1152 <_siginterrupt+0x42>
mov    0x2ebb(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     1135 <_siginterrupt+0x25>
not    %eax
and    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
neg    %eax
jmp    1157 <_siginterrupt+0x47>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i32 }
@SA_RESTART = global i32 0
define i32 @_siginterrupt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sigaction
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = call i32 @sigaction(i32 %7, %struct.sigaction* null, %struct.sigaction* %6)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %31
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* @SA_RESTART
%16 = xor i32 %15, -1
%17 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%18 = load i32, i32* %17
%19 = and i32 %18, %16
store i32 %19, i32* %17
br label %25
20: ; preds = %11
%21 = load i32, i32* @SA_RESTART
%22 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
br label %25
25: ; preds = %20, %14
%26 = load i32, i32* %4
%27 = call i32 @sigaction(i32 %26, %struct.sigaction* %6, %struct.sigaction* null)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 -1, i32* %3
br label %31
30: ; preds = %25
store i32 0, i32* %3
br label %31
31: ; preds = %30, %29, %10
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
%struct.sigaction = type { i32 }
@SA_RESTART = global i32 0
define i32 @_siginterrupt(i32 %0, i32 %1) {
%3 = alloca %struct.sigaction
%4 = bitcast %struct.sigaction* %3 to i8*
%5 = call i32 @sigaction(i32 %0, %struct.sigaction* null, %struct.sigaction* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %23, label %7
7: ; preds = %2
%8 = icmp eq i32 %1, 0
%9 = load i32, i32* @SA_RESTART
br i1 %8, label %15, label %10
10: ; preds = %7
%11 = xor i32 %9, -1
%12 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
br label %19
15: ; preds = %7
%16 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %9
store i32 %18, i32* %16
br label %19
19: ; preds = %15, %10
%20 = call i32 @sigaction(i32 %0, %struct.sigaction* %3, %struct.sigaction* null)
%21 = icmp eq i32 %20, -1
%22 = sext i1 %21 to i32
br label %23
23: ; preds = %19, %2
%24 = phi i32 [ -1, %2 ], [ %22, %19 ]
ret i32 %24
}