#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 */
typedef int pid_t;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strchr(char *, char);
scalar_t__ tgkill(int, int, int);
int main(int argc, char **argv) {
  int sig, ii;
  if (argc < 3) {
    fprintf(stderr, "usage: %s sig ppid.tid [ppid.tid [ppid.tid ...]]\n",
            argv[0]);
    exit(1);
  }
  sig = atoi(argv[1]);
  if (sig <= 0 || sig > 31) {
    fprintf(stderr, "invalid signal: %s\n", argv[1]);
    exit(1);
  }
  for (ii = 2; ii < argc; ii++) {
    char *a, *b;
    pid_t tgid, tid;
    a = argv[ii];
    b = strchr(a, '.');
    if (!b) {
      fprintf(stderr, "invalid PPID.TID '%s'\n", argv[ii]);
      continue;
    }
    *b++ = 0;
    tgid = atoi(a);
    tid = atoi(b);
    fprintf(stdout, "Sending sig %d to %d.%d\n", sig, tgid, tid);
    if (tgkill(tgid, tid, sig) < 0)
      fprintf(stderr, "Couldn't signal %d.%d\n", tgid, tid);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1198 <main+0x48>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11bc <main+0x6c>
cmpl   $0x1f,-0x14(%rbp)
jle    11e5 <main+0x95>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12e0 <main+0x190>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124d <main+0xfd>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12d2 <main+0x182>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <tgkill@plt>
cmp    $0x0,%rax
jge    12cd <main+0x17d>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12d2 <main+0x182>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ec <main+0x9c>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jle    1263 <main+0x113>
mov    %edi,%ebp
mov    %rsi,(%rsp)
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
lea    -0x20(%r15),%eax
cmp    $0xffffffe1,%eax
jb     1278 <main+0x128>
mov    %ebp,%r12d
mov    $0x2,%r14d
mov    (%rsp),%rbx
jmp    11c7 <main+0x77>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%r14
cmp    %r14,%r12
je     1252 <main+0x102>
mov    (%rbx,%r14,8),%rbp
mov    %rbp,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11a0 <main+0x50>
mov    %rax,%rbx
add    $0x1,%rbx
movb   $0x0,(%rax)
mov    %rbp,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    (%rsp),%rbx
call   1060 <atoi@plt>
mov    %eax,%r13d
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %r13d,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
mov    %r13d,%esi
mov    %r15d,%edx
call   1040 <tgkill@plt>
test   %rax,%rax
jns    11ba <main+0x6a>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
mov    %ebp,%edx
mov    %r13d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11ba <main+0x6a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd8a(%rip),%rsi
jmp    128b <main+0x13b>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [50 x i8] c"usage: %s sig ppid.tid [ppid.tid [ppid.tid ...]]\0A\00"
@.str.1 = [20 x i8] c"invalid signal: %s\0A\00"
@.str.2 = [23 x i8] c"invalid PPID.TID '%s'\0A\00"
@stdout = global i32 0
@.str.3 = [25 x i8] c"Sending sig %d to %d.%d\0A\00"
@.str.4 = [23 x i8] c"Couldn't signal %d.%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp sle i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %21
%29 = load i32, i32* %6
%30 = icmp sgt i32 %29, 31
br i1 %30, label %31, label %38
31: ; preds = %28, %21
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
store i32 2, i32* %7
br label %39
39: ; preds = %84, %38
%40 = load i32, i32* %7
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %87
43: ; preds = %39
%44 = load i8**, i8*** %5
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
%48 = load i8*, i8** %47
store i8* %48, i8** %8
%49 = load i8*, i8** %8
%50 = call i8* @strchr(i8* %49, i8 signext 46)
store i8* %50, i8** %9
%51 = load i8*, i8** %9
%52 = icmp ne i8* %51, null
br i1 %52, label %61, label %53
53: ; preds = %43
%54 = load i32, i32* @stderr
%55 = load i8**, i8*** %5
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %59)
br label %84
61: ; preds = %43
%62 = load i8*, i8** %9
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %9
store i8 0, i8* %62
%64 = load i8*, i8** %8
%65 = call i32 @atoi(i8* %64)
store i32 %65, i32* %10
%66 = load i8*, i8** %9
%67 = call i32 @atoi(i8* %66)
store i32 %67, i32* %11
%68 = load i32, i32* @stdout
%69 = load i32, i32* %6
%70 = load i32, i32* %10
%71 = load i32, i32* %11
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %69, i32 %70, i32 %71)
%73 = load i32, i32* %10
%74 = load i32, i32* %11
%75 = load i32, i32* %6
%76 = call i64 @tgkill(i32 %73, i32 %74, i32 %75)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %61
%79 = load i32, i32* @stderr
%80 = load i32, i32* %10
%81 = load i32, i32* %11
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %80, i32 %81)
br label %83
83: ; preds = %78, %61
br label %84
84: ; preds = %83, %53
%85 = load i32, i32* %7
%86 = add nsw i32 %85, 1
store i32 %86, i32* %7
br label %39
87: ; preds = %39
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [50 x i8] c"usage: %s sig ppid.tid [ppid.tid [ppid.tid ...]]\0A\00"
@.str.1 = [20 x i8] c"invalid signal: %s\0A\00"
@.str.2 = [23 x i8] c"invalid PPID.TID '%s'\0A\00"
@stdout = global i32 0
@.str.3 = [25 x i8] c"Sending sig %d to %d.%d\0A\00"
@.str.4 = [23 x i8] c"Couldn't signal %d.%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = add i32 %12, -32
%14 = icmp ult i32 %13, -31
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = zext i32 %0 to i64
br label %21
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %15, %41
%22 = phi i64 [ 2, %15 ], [ %42, %41 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i8* @strchr(i8* dereferenceable(1) %24, i8 signext 46)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %41
30: ; preds = %21
%31 = getelementptr inbounds i8, i8* %25, i64 1
store i8 0, i8* %25
%32 = tail call i32 @atoi(i8* %24)
%33 = tail call i32 @atoi(i8* %31)
%34 = load i32, i32* @stdout
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 %32, i32 %33)
%36 = tail call i64 @tgkill(i32 %32, i32 %33, i32 %12)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %32, i32 %33)
br label %41
41: ; preds = %30, %38, %27
%42 = add nuw nsw i64 %22, 1
%43 = icmp eq i64 %42, %16
br i1 %43, label %44, label %21
44: ; preds = %41
ret i32 0
}