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


x86 assembly (clang, -O0):
<siginterrupt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdx
call   1030 <sigaction@plt>
cmpl   $0x0,-0x8(%rbp)
je     114f <siginterrupt+0x3f>
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    115e <siginterrupt+0x4e>
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
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>
mov    0x2ec0(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     1135 <siginterrupt+0x25>
not    %eax
and    %eax,(%rsp)
jmp    1138 <siginterrupt+0x28>
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 %struct.sigaction
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i32 @sigaction(i32 %6, %struct.sigaction* null, %struct.sigaction* %5)
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @SA_RESTART
%12 = xor i32 %11, -1
%13 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
%14 = load i32, i32* %13
%15 = and i32 %14, %12
store i32 %15, i32* %13
br label %21
16: ; preds = %2
%17 = load i32, i32* @SA_RESTART
%18 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %5, i32 0, i32 0
%19 = load i32, i32* %18
%20 = or i32 %19, %17
store i32 %20, i32* %18
br label %21
21: ; preds = %16, %10
%22 = load i32, i32* %3
%23 = call i32 @sigaction(i32 %22, %struct.sigaction* %5, %struct.sigaction* null)
ret i32 %23
}

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 %1, 0
%7 = load i32, i32* @SA_RESTART
br i1 %6, label %13, label %8
8: ; preds = %2
%9 = xor i32 %7, -1
%10 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = and i32 %11, %9
store i32 %12, i32* %10
br label %17
13: ; preds = %2
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = or i32 %15, %7
store i32 %16, i32* %14
br label %17
17: ; preds = %13, %8
%18 = call i32 @sigaction(i32 %0, %struct.sigaction* %3, %struct.sigaction* null)
ret i32 %18
}