#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 sig, int flag) {
  int status;
  struct sigaction act;
  status = sigaction(sig, NULL, &act);
  if (status == -1)
    return -1;
  if (flag)
    act.sa_flags &= ~SA_RESTART;
  else
    act.sa_flags |= SA_RESTART;
  return sigaction(sig, &act, NULL);
}


x86 assembly (clang, -O0):
<siginterrupt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
call   1030 <sigaction@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1147 <siginterrupt+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <siginterrupt+0x7a>
cmpl   $0x0,-0xc(%rbp)
je     1168 <siginterrupt+0x58>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1177 <siginterrupt+0x67>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%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     113a <siginterrupt+0x2a>
mov    0x2ebb(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     1141 <siginterrupt+0x31>
not    %eax
and    %eax,(%rsp)
jmp    1144 <siginterrupt+0x34>
mov    $0xffffffff,%eax
jmp    1150 <siginterrupt+0x40>
or     %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <sigaction@plt>
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 i32
%7 = alloca %struct.sigaction
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = call i32 @sigaction(i32 %8, %struct.sigaction* null, %struct.sigaction* %7)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %30
13: ; preds = %2
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i32, i32* @SA_RESTART
%18 = xor i32 %17, -1
%19 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %7, i32 0, i32 0
%20 = load i32, i32* %19
%21 = and i32 %20, %18
store i32 %21, i32* %19
br label %27
22: ; preds = %13
%23 = load i32, i32* @SA_RESTART
%24 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %7, i32 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
br label %27
27: ; preds = %22, %16
%28 = load i32, i32* %4
%29 = call i32 @sigaction(i32 %28, %struct.sigaction* %7, %struct.sigaction* null)
store i32 %29, i32* %3
br label %30
30: ; preds = %27, %12
%31 = load i32, i32* %3
ret i32 %31
}

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 %21, 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 = or 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)
br label %21
21: ; preds = %2, %19
%22 = phi i32 [ %20, %19 ], [ -1, %2 ]
ret i32 %22
}