#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 */
union sigval {
  int sival_int;
};

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ get_pids_by_name(char const *, int *);
int getopt(int, char **, char const *);
char *optarg;
int /*<<< orphan*/ printf(char *, int, ...);
scalar_t__ sigqueue(int, int, union sigval);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  const char *name = NULL;
  int pids[1024] = {0};
  int vid = -1;
  int sig = -1;
  static const char *shortopts = "v:s:p:n:";
  while (1) {
    int opt = getopt(argc, argv, shortopts);
    if (-1 == opt) {
      break;
    }
    switch (opt) {
    case 'v':
      vid = atoi(optarg);
      break;
    case 's':
      sig = atoi(optarg);
      break;
    case 'p':
      pids[0] = atoi(optarg);
      break;
    case 'n':
      name = optarg;
      if (get_pids_by_name(name, pids)) {
        return 0;
      }
      break;
    default:
      break;
    }
  }
  printf("vid=%d sig=%d\n", vid, sig);
  if (-1 == vid || -1 == sig) {
    fprintf(stderr, "Error : invalid params\n");
    return -1;
  }
  union sigval value;
  value.sival_int = vid;
  int i = 0;
  for (; 0 != pids[i]; i++) {
    printf("pid = %d\n", pids[i]);
    if (0 != sigqueue(pids[i], sig, value)) {
      fprintf(stderr, "Error : send error\n");
      return -2;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
movl   $0xffffffff,-0x1024(%rbp)
ff ff ff
movl   $0xffffffff,-0x1028(%rbp)
ff ff ff
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e92(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x102c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x102c(%rbp),%eax
jne    11e7 <main+0x77>
jmp    12a9 <main+0x139>
mov    -0x102c(%rbp),%eax
add    $0xffffff92,%eax
mov    %eax,%ecx
mov    %rcx,-0x1040(%rbp)
sub    $0x8,%eax
ja     129f <main+0x12f>
mov    -0x1040(%rbp),%rax
lea    0xdf0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dd8(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1024(%rbp)
jmp    12a4 <main+0x134>
mov    0x2dbe(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1028(%rbp)
jmp    12a4 <main+0x134>
mov    0x2da4(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1020(%rbp)
jmp    12a4 <main+0x134>
mov    0x2d8a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
call   1050 <get_pids_by_name@plt>
cmp    $0x0,%eax
je     129a <main+0x12a>
movl   $0x0,-0x4(%rbp)
jmp    13bc <main+0x24c>
jmp    12a4 <main+0x134>
jmp    12a4 <main+0x134>
jmp    11b8 <main+0x48>
mov    -0x1024(%rbp),%esi
mov    -0x1028(%rbp),%edx
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%eax
cmp    -0x1024(%rbp),%eax
je     12e5 <main+0x175>
mov    $0xffffffff,%eax
cmp    -0x1028(%rbp),%eax
jne    1306 <main+0x196>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13bc <main+0x24c>
mov    -0x1024(%rbp),%eax
mov    %eax,-0x1030(%rbp)
movl   $0x0,-0x1034(%rbp)
movslq -0x1034(%rbp),%rcx
xor    %eax,%eax
cmp    -0x1020(%rbp,%rcx,4),%eax
je     13b5 <main+0x245>
movslq -0x1034(%rbp),%rax
mov    -0x1020(%rbp,%rax,4),%esi
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x1034(%rbp),%rax
mov    -0x1020(%rbp,%rax,4),%edi
mov    -0x1028(%rbp),%esi
mov    -0x1030(%rbp),%edx
call   1070 <sigqueue@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     139c <main+0x22c>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
lea    0xcd3(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    13bc <main+0x24c>
jmp    13a1 <main+0x231>
mov    -0x1034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1034(%rbp)
jmp    131c <main+0x1ac>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x10(%rsp),%r12
mov    $0x1000,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xe7b(%rip),%r13
lea    0xe50(%rip),%r14
mov    0x2e41(%rip),%r15
movl   $0xffffffff,0x8(%rsp)
ff
jmp    11dc <main+0x6c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r13,%rdx
call   1080 <getopt@plt>
lea    -0x6e(%rax),%ecx
cmp    $0x8,%ecx
ja     120e <main+0x9e>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
mov    (%r15),%rdi
mov    %r12,%rsi
call   1050 <get_pids_by_name@plt>
test   %eax,%eax
je     11dc <main+0x6c>
jmp    12a6 <main+0x136>
cmp    $0xffffffff,%eax
jne    11dc <main+0x6c>
jmp    1231 <main+0xc1>
mov    (%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,0x8(%rsp)
jmp    11dc <main+0x6c>
mov    (%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    11dc <main+0x6c>
lea    0xdf5(%rip),%rdi
mov    0xc(%rsp),%ebp
mov    %ebp,%esi
mov    0x8(%rsp),%r12d
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
lea    0xde3(%rip),%r14
cmp    $0xffffffff,%ebp
je     12af <main+0x13f>
cmp    $0xffffffff,%r12d
je     12af <main+0x13f>
mov    0x10(%rsp),%esi
test   %esi,%esi
je     12a6 <main+0x136>
lea    0x14(%rsp),%rbx
lea    0xddc(%rip),%r15
lea    0xddf(%rip),%r14
nop
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x4(%rbx),%edi
mov    %r12d,%esi
mov    %ebp,%edx
call   1070 <sigqueue@plt>
test   %rax,%rax
jne    12aa <main+0x13a>
mov    (%rbx),%esi
add    $0x4,%rbx
test   %esi,%esi
jne    1280 <main+0x110>
xor    %ebx,%ebx
jmp    12c0 <main+0x150>
mov    $0xfffffffe,%ebx
mov    0x2d22(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1060 <fprintf@plt>
mov    %ebx,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.sigval = type { i32 }
@main.shortopts = internal global i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0)
@.str = [9 x i8] c"v:s:p:n:\00"
@optarg = global i8* null
@.str.1 = [15 x i8] c"vid=%d sig=%d\0A\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Error : invalid params\0A\00"
@.str.3 = [10 x i8] c"pid = %d\0A\00"
@.str.4 = [20 x i8] c"Error : send error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [1024 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %union.sigval
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%13 = bitcast [1024 x i32]* %7 to i8*
store i32 -1, i32* %8
store i32 -1, i32* %9
br label %14
14: ; preds = %2, %43
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = load i8*, i8** @main.shortopts
%18 = call i32 @getopt(i32 %15, i8** %16, i8* %17)
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = icmp eq i32 -1, %19
br i1 %20, label %21, label %22
21: ; preds = %14
br label %44
22: ; preds = %14
%23 = load i32, i32* %10
switch i32 %23, label %42 [
i32 118, label %24
i32 115, label %27
i32 112, label %30
i32 110, label %34
]
24: ; preds = %22
%25 = load i8*, i8** @optarg
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %8
br label %43
27: ; preds = %22
%28 = load i8*, i8** @optarg
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %9
br label %43
30: ; preds = %22
%31 = load i8*, i8** @optarg
%32 = call i32 @atoi(i8* %31)
%33 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
store i32 %32, i32* %33
br label %43
34: ; preds = %22
%35 = load i8*, i8** @optarg
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 0
%38 = call i32 @get_pids_by_name(i8* %36, i32* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 0, i32* %3
br label %88
41: ; preds = %34
br label %43
42: ; preds = %22
br label %43
43: ; preds = %42, %41, %30, %27, %24
br label %14
44: ; preds = %21
%45 = load i32, i32* %8
%46 = load i32, i32* %9
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %45, i32 %46)
%48 = load i32, i32* %8
%49 = icmp eq i32 -1, %48
br i1 %49, label %53, label %50
50: ; preds = %44
%51 = load i32, i32* %9
%52 = icmp eq i32 -1, %51
br i1 %52, label %53, label %56
53: ; preds = %50, %44
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %88
56: ; preds = %50
%57 = load i32, i32* %8
%58 = bitcast %union.sigval* %11 to i32*
store i32 %57, i32* %58
store i32 0, i32* %12
br label %59
59: ; preds = %84, %56
%60 = load i32, i32* %12
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = icmp ne i32 0, %63
br i1 %64, label %65, label %87
65: ; preds = %59
%66 = load i32, i32* %12
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %69)
%71 = load i32, i32* %12
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [1024 x i32], [1024 x i32]* %7, i64 0, i64 %72
%74 = load i32, i32* %73
%75 = load i32, i32* %9
%76 = getelementptr inbounds %union.sigval, %union.sigval* %11, i32 0, i32 0
%77 = load i32, i32* %76
%78 = call i64 @sigqueue(i32 %74, i32 %75, i32 %77)
%79 = icmp ne i64 0, %78
br i1 %79, label %80, label %83
80: ; preds = %65
%81 = load i32, i32* @stderr
%82 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 -2, i32* %3
br label %88
83: ; preds = %65
br label %84
84: ; preds = %83
%85 = load i32, i32* %12
%86 = add nsw i32 %85, 1
store i32 %86, i32* %12
br label %59
87: ; preds = %59
store i32 0, i32* %3
br label %88
88: ; preds = %87, %80, %53, %40
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@.str = [9 x i8] c"v:s:p:n:\00"
@optarg = global i8* null
@.str.1 = [15 x i8] c"vid=%d sig=%d\0A\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Error : invalid params\0A\00"
@.str.3 = [10 x i8] c"pid = %d\0A\00"
@.str.4 = [20 x i8] c"Error : send error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i32]
%4 = bitcast [1024 x i32]* %3 to i8*
%5 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 0
br label %6
6: ; preds = %13, %2
%7 = phi i32 [ %15, %13 ], [ -1, %2 ]
%8 = phi i32 [ %10, %13 ], [ -1, %2 ]
br label %9
9: ; preds = %6, %16
%10 = phi i32 [ %8, %6 ], [ %18, %16 ]
br label %11
11: ; preds = %22, %9
%12 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
switch i32 %12, label %22 [
i32 -1, label %27
i32 118, label %13
i32 115, label %16
i32 112, label %19
i32 110, label %23
]
13: ; preds = %11
%14 = load i8*, i8** @optarg
%15 = call i32 @atoi(i8* %14)
br label %6
16: ; preds = %11
%17 = load i8*, i8** @optarg
%18 = call i32 @atoi(i8* %17)
br label %9
19: ; preds = %11
%20 = load i8*, i8** @optarg
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %5
br label %22
22: ; preds = %19, %23, %11
br label %11
23: ; preds = %11
%24 = load i8*, i8** @optarg
%25 = call i32 @get_pids_by_name(i8* %24, i32* %5)
%26 = icmp eq i32 %25, 0
br i1 %26, label %22, label %53
27: ; preds = %11
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %10)
%29 = icmp eq i32 %7, -1
%30 = icmp eq i32 %10, -1
%31 = select i1 %29, i1 true, i1 %30
br i1 %31, label %48, label %32
32: ; preds = %27
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 0
br i1 %34, label %53, label %39
35: ; preds = %39
%36 = getelementptr inbounds [1024 x i32], [1024 x i32]* %3, i64 0, i64 %47
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, 0
br i1 %38, label %53, label %39
39: ; preds = %32, %35
%40 = phi i64 [ %47, %35 ], [ 0, %32 ]
%41 = phi i32 [ %37, %35 ], [ %33, %32 ]
%42 = phi i32* [ %36, %35 ], [ %5, %32 ]
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%44 = load i32, i32* %42
%45 = call i64 @sigqueue(i32 %44, i32 %10, i32 %7)
%46 = icmp eq i64 %45, 0
%47 = add nuw i64 %40, 1
br i1 %46, label %35, label %48
48: ; preds = %39, %27
%49 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), %27 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), %39 ]
%50 = phi i32 [ -1, %27 ], [ -2, %39 ]
%51 = load i32, i32* @stderr
%52 = call i32 @fprintf(i32 %51, i8* %49)
br label %53
53: ; preds = %23, %35, %48, %32
%54 = phi i32 [ 0, %32 ], [ %50, %48 ], [ 0, %35 ], [ 0, %23 ]
ret i32 %54
}