#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 /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SIGUSR1;
int /*<<< orphan*/ SIGUSR2;
scalar_t__ access(char *, int /*<<< orphan*/);
int atoi(char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  pid_t pid;
  char *s;
  if (argc != 2) {
    fputs("***** usage: sendsig <1|2|t>\n", stderr);
    return (1);
  }
  if (!(s = getenv("WNKPID")) || !(pid = atoi(s))) {
    fputs("***** sendsig: missing WNKPID\n", stderr);
    return (1);
  }
  {
    char sx[1024];
    sprintf(sx, "ps -W >>/eval/pids.tmp/%d", pid);
    system(sx);
  }
  if (*argv[1] == '1')
    kill(pid, SIGUSR1);
  else if (access("killed.tmp", 0))
    kill(pid, (*argv[1] == 't') ? SIGTERM : SIGUSR2);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b4 <main+0x44>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    0xe5d(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c5 <main+0x155>
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11e3 <main+0x73>
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1204 <main+0x94>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe32(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c5 <main+0x155>
lea    -0x420(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe2f(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <system@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
jne    1250 <main+0xe0>
mov    -0x14(%rbp),%edi
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    12be <main+0x14e>
lea    0xe07(%rip),%rdi
xor    %esi,%esi
call   1070 <access@plt>
cmp    $0x0,%rax
je     12b9 <main+0x149>
mov    -0x14(%rbp),%eax
mov    %eax,-0x424(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x74,%eax
jne    1299 <main+0x129>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
jmp    12a8 <main+0x138>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    -0x424(%rbp),%edi
mov    -0x428(%rbp),%esi
call   1060 <kill@plt>
jmp    12be <main+0x14e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
cmp    $0x2,%edi
jne    11dd <main+0x6d>
mov    %rsi,%rbx
lea    0xe94(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ef <main+0x7f>
mov    %rax,%rdi
call   1080 <atoi@plt>
test   %eax,%eax
je     11ef <main+0x7f>
mov    %eax,%r14d
lea    0xe9a(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <system@plt>
mov    0x8(%rbx),%rax
cmpb   $0x31,(%rax)
jne    1217 <main+0xa7>
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1060 <kill@plt>
xor    %ebp,%ebp
jmp    1209 <main+0x99>
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
lea    0xe13(%rip),%rdi
jmp    11ff <main+0x8f>
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
lea    0xe26(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe40(%rip),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
call   1070 <access@plt>
test   %rax,%rax
je     1209 <main+0x99>
mov    0x8(%rbx),%rax
cmpb   $0x74,(%rax)
jne    123e <main+0xce>
mov    0x2da4(%rip),%rax
jmp    1245 <main+0xd5>
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1060 <kill@plt>
jmp    1209 <main+0x99>

LLVM IR (-O0):
@.str = [30 x i8] c"***** usage: sendsig <1|2|t>\0A\00"
@stderr = global i32 0
@.str.1 = [7 x i8] c"WNKPID\00"
@.str.2 = [31 x i8] c"***** sendsig: missing WNKPID\0A\00"
@.str.3 = [26 x i8] c"ps -W >>/eval/pids.tmp/%d\00"
@SIGUSR1 = global i32 0
@.str.4 = [11 x i8] c"killed.tmp\00"
@SIGTERM = global i32 0
@SIGUSR2 = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 1, i32* %3
br label %60
14: ; preds = %2
%15 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %7
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i8*, i8** %7
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17, %14
%22 = load i32, i32* @stderr
%23 = call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %22)
store i32 1, i32* %3
br label %60
24: ; preds = %17
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%26 = load i32, i32* %6
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%29 = call i32 @system(i8* %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 49
br i1 %35, label %36, label %40
36: ; preds = %24
%37 = load i32, i32* %6
%38 = load i32, i32* @SIGUSR1
%39 = call i32 @kill(i32 %37, i32 %38)
br label %59
40: ; preds = %24
%41 = call i64 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 0)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %58
43: ; preds = %40
%44 = load i32, i32* %6
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 116
br i1 %50, label %51, label %53
51: ; preds = %43
%52 = load i32, i32* @SIGTERM
br label %55
53: ; preds = %43
%54 = load i32, i32* @SIGUSR2
br label %55
55: ; preds = %53, %51
%56 = phi i32 [ %52, %51 ], [ %54, %53 ]
%57 = call i32 @kill(i32 %44, i32 %56)
br label %58
58: ; preds = %55, %40
br label %59
59: ; preds = %58, %36
store i32 0, i32* %3
br label %60
60: ; preds = %59, %21, %11
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@.str = [30 x i8] c"***** usage: sendsig <1|2|t>\0A\00"
@stderr = global i32 0
@.str.1 = [7 x i8] c"WNKPID\00"
@.str.2 = [31 x i8] c"***** sendsig: missing WNKPID\0A\00"
@.str.3 = [26 x i8] c"ps -W >>/eval/pids.tmp/%d\00"
@SIGUSR1 = global i32 0
@.str.4 = [11 x i8] c"killed.tmp\00"
@SIGTERM = global i32 0
@SIGUSR2 = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputs(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %39
8: ; preds = %2
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @atoi(i8* %9)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11, %8
%15 = load i32, i32* @stderr
%16 = tail call i32 @fputs(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %39
17: ; preds = %11
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = call i32 @sprintf(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%20 = call i32 @system(i8* %18)
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 49
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load i32, i32* @SIGUSR1
%27 = tail call i32 @kill(i32 %12, i32 %26)
br label %39
28: ; preds = %17
%29 = tail call i64 @access(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %39, label %31
31: ; preds = %28
%32 = load i8*, i8** %21
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 116
%35 = load i32, i32* @SIGTERM
%36 = load i32, i32* @SIGUSR2
%37 = select i1 %34, i32 %35, i32 %36
%38 = tail call i32 @kill(i32 %12, i32 %37)
br label %39
39: ; preds = %25, %31, %28, %14, %5
%40 = phi i32 [ 1, %5 ], [ 1, %14 ], [ 0, %28 ], [ 0, %31 ], [ 0, %25 ]
ret i32 %40
}