#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 {
  void *sa_sigaction;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SIGUSR1;
scalar_t__ SIG_DFL;
int atoi(char *);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getprogname();
int /*<<< orphan*/ printf(char *, char *, int, ...);
int read(int, char *, int);
scalar_t__ sigaction(int /*<<< orphan*/, int /*<<< orphan*/ *,
                     struct sigaction *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigismember(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                       int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int parent_pipe, res = EXIT_SUCCESS;
  sigset_t sig;
  struct sigaction act;
  ssize_t rd;
  char tmp;
  sigemptyset(&sig);
  if (sigprocmask(0, NULL, &sig) < 0) {
    fprintf(stderr, "%s: sigprocmask error\n", getprogname());
    res = EXIT_FAILURE;
  }
  if (!sigismember(&sig, SIGUSR1)) {
    fprintf(stderr, "%s: SIGUSR not in procmask\n", getprogname());
    res = EXIT_FAILURE;
  }
  if (sigaction(SIGUSR1, NULL, &act) < 0) {
    fprintf(stderr, "%s: sigaction error\n", getprogname());
    res = EXIT_FAILURE;
  }
  if (act.sa_sigaction != (void *)SIG_DFL) {
    fprintf(stderr, "%s: SIGUSR1 action != SIG_DFL\n", getprogname());
    res = EXIT_FAILURE;
  }
  if (argc >= 2) {
    parent_pipe = atoi(argv[1]);
    if (parent_pipe > 2) {
      printf("%s: waiting for command from parent on pipe "
             "%d\n",
             getprogname(), parent_pipe);
      rd = read(parent_pipe, &tmp, 1);
      if (rd == 1) {
        printf("%s: got command %c from parent\n", getprogname(), tmp);
      } else if (rd == -1) {
        printf("%s: %d is no pipe, errno %d\n", getprogname(), parent_pipe,
               errno);
        res = EXIT_FAILURE;
      }
    }
  }
  return res;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1090 <sigemptyset@plt>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x1c(%rbp),%rdx
call   1030 <sigprocmask@plt>
cmp    $0x0,%rax
jge    1205 <main+0x75>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1050 <getprogname@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe0c(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdi
call   10b0 <sigismember@plt>
cmp    $0x0,%eax
jne    1251 <main+0xc1>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <getprogname@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xdd7(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x28(%rbp),%rdx
call   1040 <sigaction@plt>
cmp    $0x0,%rax
jge    12a2 <main+0x112>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1050 <getprogname@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xda2(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2d13(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rax
je     12ea <main+0x15a>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    $0x0,%al
call   1050 <getprogname@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xd6f(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     13b1 <main+0x221>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jle    13ac <main+0x21c>
mov    $0x0,%al
call   1050 <getprogname@plt>
mov    %rax,%rsi
mov    -0x14(%rbp),%edx
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    1368 <main+0x1d8>
mov    $0x0,%al
call   1050 <getprogname@plt>
mov    %rax,%rsi
movsbl -0x2d(%rbp),%edx
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13a7 <main+0x217>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    13a2 <main+0x212>
mov    $0x0,%al
call   1050 <getprogname@plt>
mov    %rax,%rsi
mov    -0x14(%rbp),%edx
mov    0x2c4a(%rip),%rax
mov    (%rax),%ecx
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    13a7 <main+0x217>
jmp    13ac <main+0x21c>
jmp    13b1 <main+0x221>
mov    -0x18(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2e11(%rip),%rax
mov    (%rax),%ebp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <sigemptyset@plt>
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <sigprocmask@plt>
test   %rax,%rax
jns    11f1 <main+0x61>
mov    0x2e0a(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1050 <getprogname@plt>
lea    0xe22(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%ebp
mov    0x2df0(%rip),%rbx
mov    (%rbx),%esi
lea    0xc(%rsp),%rdi
call   10b0 <sigismember@plt>
test   %eax,%eax
jne    1232 <main+0xa2>
mov    0x2dc9(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1050 <getprogname@plt>
lea    0xdf8(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%edi
lea    0x10(%rsp),%rdx
xor    %esi,%esi
call   1040 <sigaction@plt>
test   %rax,%rax
jns    126f <main+0xdf>
mov    0x2d8c(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1050 <getprogname@plt>
lea    0xdd7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%rsp),%rax
mov    0x2d45(%rip),%rcx
cmp    (%rcx),%rax
je     12aa <main+0x11a>
mov    0x2d51(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1050 <getprogname@plt>
lea    0xdb1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%ebp
cmp    $0x2,%r15d
jl     1348 <main+0x1b8>
mov    0x8(%r14),%rdi
call   10a0 <atoi@plt>
cmp    $0x3,%eax
jl     1348 <main+0x1b8>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getprogname@plt>
lea    0xd91(%rip),%rdi
mov    %rax,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xb(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     131c <main+0x18c>
cmp    $0x1,%eax
jne    1348 <main+0x1b8>
xor    %eax,%eax
call   1050 <getprogname@plt>
movsbl 0xb(%rsp),%edx
lea    0xd87(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1348 <main+0x1b8>
xor    %eax,%eax
call   1050 <getprogname@plt>
mov    0x2ca6(%rip),%rcx
mov    (%rcx),%ecx
lea    0xd84(%rip),%rdi
mov    %rax,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { i8* }
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"%s: sigprocmask error\0A\00"
@EXIT_FAILURE = global i32 0
@SIGUSR1 = global i32 0
@.str.1 = [28 x i8] c"%s: SIGUSR not in procmask\0A\00"
@.str.2 = [21 x i8] c"%s: sigaction error\0A\00"
@SIG_DFL = global i64 0
@.str.3 = [31 x i8] c"%s: SIGUSR1 action != SIG_DFL\0A\00"
@.str.4 = [48 x i8] c"%s: waiting for command from parent on pipe %d\0A\00"
@.str.5 = [32 x i8] c"%s: got command %c from parent\0A\00"
@.str.6 = [29 x i8] c"%s: %d is no pipe, errno %d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sigaction
%10 = alloca i32
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @EXIT_SUCCESS
store i32 %12, i32* %7
%13 = call i32 @sigemptyset(i32* %8)
%14 = call i64 @sigprocmask(i32 0, i32* null, i32* %8)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i8* (...) @getprogname()
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %7
br label %21
21: ; preds = %16, %2
%22 = load i32, i32* @SIGUSR1
%23 = call i32 @sigismember(i32* %8, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i8* (...) @getprogname()
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %7
br label %30
30: ; preds = %25, %21
%31 = load i32, i32* @SIGUSR1
%32 = call i64 @sigaction(i32 %31, i32* null, %struct.sigaction* %9)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i8* (...) @getprogname()
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
store i32 %38, i32* %7
br label %39
39: ; preds = %34, %30
%40 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %9, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = load i64, i64* @SIG_DFL
%43 = inttoptr i64 %42 to i8*
%44 = icmp ne i8* %41, %43
br i1 %44, label %45, label %50
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = call i8* (...) @getprogname()
%48 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_FAILURE
store i32 %49, i32* %7
br label %50
50: ; preds = %45, %39
%51 = load i32, i32* %4
%52 = icmp sge i32 %51, 2
br i1 %52, label %53, label %85
53: ; preds = %50
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i32 @atoi(i8* %56)
store i32 %57, i32* %6
%58 = load i32, i32* %6
%59 = icmp sgt i32 %58, 2
br i1 %59, label %60, label %84
60: ; preds = %53
%61 = call i8* (...) @getprogname()
%62 = load i32, i32* %6
%63 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %61, i32 %62)
%64 = load i32, i32* %6
%65 = call i32 @read(i32 %64, i8* %11, i32 1)
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %73
68: ; preds = %60
%69 = call i8* (...) @getprogname()
%70 = load i8, i8* %11
%71 = sext i8 %70 to i32
%72 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %69, i32 %71)
br label %83
73: ; preds = %60
%74 = load i32, i32* %10
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %82
76: ; preds = %73
%77 = call i8* (...) @getprogname()
%78 = load i32, i32* %6
%79 = load i32, i32* @errno
%80 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %77, i32 %78, i32 %79)
%81 = load i32, i32* @EXIT_FAILURE
store i32 %81, i32* %7
br label %82
82: ; preds = %76, %73
br label %83
83: ; preds = %82, %68
br label %84
84: ; preds = %83, %53
br label %85
85: ; preds = %84, %50
%86 = load i32, i32* %7
ret i32 %86
}

LLVM IR (-O2):
%struct.sigaction = type { i8* }
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"%s: sigprocmask error\0A\00"
@EXIT_FAILURE = global i32 0
@SIGUSR1 = global i32 0
@.str.1 = [28 x i8] c"%s: SIGUSR not in procmask\0A\00"
@.str.2 = [21 x i8] c"%s: sigaction error\0A\00"
@SIG_DFL = global i64 0
@.str.3 = [31 x i8] c"%s: SIGUSR1 action != SIG_DFL\0A\00"
@.str.4 = [48 x i8] c"%s: waiting for command from parent on pipe %d\0A\00"
@.str.5 = [32 x i8] c"%s: got command %c from parent\0A\00"
@.str.6 = [29 x i8] c"%s: %d is no pipe, errno %d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sigaction
%5 = alloca i8
%6 = load i32, i32* @EXIT_SUCCESS
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sigaction* %4 to i8*
%9 = call i32 @sigemptyset(i32* %3)
%10 = call i64 @sigprocmask(i32 0, i32* null, i32* %3)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i8* (...) @getprogname()
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
br label %17
17: ; preds = %12, %2
%18 = phi i32 [ %16, %12 ], [ %6, %2 ]
%19 = load i32, i32* @SIGUSR1
%20 = call i32 @sigismember(i32* %3, i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = call i8* (...) @getprogname()
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
br label %27
27: ; preds = %22, %17
%28 = phi i32 [ %18, %17 ], [ %26, %22 ]
%29 = load i32, i32* @SIGUSR1
%30 = call i64 @sigaction(i32 %29, i32* null, %struct.sigaction* %4)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i8* (...) @getprogname()
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* @EXIT_FAILURE
br label %37
37: ; preds = %32, %27
%38 = phi i32 [ %36, %32 ], [ %28, %27 ]
%39 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i64 0, i32 0
%40 = load i8*, i8** %39
%41 = load i64, i64* @SIG_DFL
%42 = inttoptr i64 %41 to i8*
%43 = icmp eq i8* %40, %42
br i1 %43, label %49, label %44
44: ; preds = %37
%45 = load i32, i32* @stderr
%46 = call i8* (...) @getprogname()
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
br label %49
49: ; preds = %44, %37
%50 = phi i32 [ %48, %44 ], [ %38, %37 ]
%51 = icmp sgt i32 %0, 1
br i1 %51, label %52, label %71
52: ; preds = %49
%53 = getelementptr inbounds i8*, i8** %1, i64 1
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
%56 = icmp sgt i32 %55, 2
br i1 %56, label %57, label %71
57: ; preds = %52
%58 = call i8* (...) @getprogname()
%59 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %58, i32 %55)
%60 = call i32 @read(i32 %55, i8* %5, i32 1)
switch i32 %60, label %71 [
i32 1, label %61
i32 -1, label %66
]
61: ; preds = %57
%62 = call i8* (...) @getprogname()
%63 = load i8, i8* %5
%64 = sext i8 %63 to i32
%65 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %62, i32 %64)
br label %71
66: ; preds = %57
%67 = call i8* (...) @getprogname()
%68 = load i32, i32* @errno
%69 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0), i8* %67, i32 %55, i32 %68)
%70 = load i32, i32* @EXIT_FAILURE
br label %71
71: ; preds = %57, %52, %66, %61, %49
%72 = phi i32 [ %50, %61 ], [ %70, %66 ], [ %50, %52 ], [ %50, %49 ], [ %50, %57 ]
ret i32 %72
}