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


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>
mov    %eax,-0xc(%rbp)
mov    -0xc(%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>
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 i32
%6 = alloca %struct.sigaction
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i32 @sigaction(i32 %7, %struct.sigaction* null, %struct.sigaction* %6)
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @SA_RESTART
%13 = xor i32 %12, -1
%14 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%15 = load i32, i32* %14
%16 = and i32 %15, %13
store i32 %16, i32* %14
br label %22
17: ; preds = %2
%18 = load i32, i32* @SA_RESTART
%19 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %6, i32 0, i32 0
%20 = load i32, i32* %19
%21 = or i32 %20, %18
store i32 %21, i32* %19
br label %22
22: ; preds = %17, %11
%23 = load i32, i32* %3
%24 = call i32 @sigaction(i32 %23, %struct.sigaction* %6, %struct.sigaction* null)
store i32 %24, i32* %5
%25 = load i32, i32* %5
ret i32 %25
}

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
}