#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 */

/* Variables and functions */
int SIGTERM;
int /*<<< orphan*/ SYS_tgkill;
int atoi(char *);
int /*<<< orphan*/ printf(char *);
int syscall(int /*<<< orphan*/, int, int, int);
int main(int argc, char *argv[]) {
  int sig = SIGTERM;
  int tgid = -1;
  int tid;
  if (argc == 1) {
    printf("Usage: %s [-SIGNUM] [<tgid>] <tid>\n, argv[0]");
    return 1;
  } else if (argc == 2) {
    tid = atoi(argv[1]);
  } else if (argc == 3) {
    tgid = atoi(argv[1]);
    tid = atoi(argv[2]);
  } else if (argc == 4) {
    sig = -atoi(argv[1]);
    tgid = atoi(argv[2]);
    tid = atoi(argv[3]);
  }
  return syscall(SYS_tgkill, tgid, tid, sig);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    117b <main+0x4b>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1232 <main+0x102>
cmpl   $0x2,-0x8(%rbp)
jne    119a <main+0x6a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1213 <main+0xe3>
cmpl   $0x3,-0x8(%rbp)
jne    11c9 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    120e <main+0xde>
cmpl   $0x4,-0x8(%rbp)
jne    1209 <main+0xd9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    120e <main+0xde>
jmp    1213 <main+0xe3>
jmp    1218 <main+0xe8>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1040 <syscall@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2ea7(%rip),%rax
mov    (%rax),%r14d
mov    $0x2,%r15d
mov    $0xffffffff,%ebp
mov    $0x1,%eax
add    $0xffffffff,%edi
lea    0xea2(%rip),%rcx
movslq (%rcx,%rdi,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
neg    %r14d
mov    $0x3,%r15d
mov    $0x2,%eax
mov    (%rbx,%rax,8),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
mov    %r15,%rax
mov    (%rbx,%rax,8),%rdi
call   1050 <atoi@plt>
mov    0x2e25(%rip),%rcx
mov    (%rcx),%edi
mov    %ebp,%esi
mov    %eax,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <syscall@plt>

LLVM IR (-O0):
@SIGTERM = global i32 0
@.str = [45 x i8] c"Usage: %s [-SIGNUM] [<tgid>] <tid>\0A, argv[0]\00"
@SYS_tgkill = 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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @SIGTERM
store i32 %9, i32* %6
store i32 -1, i32* %7
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %60
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %8
br label %53
22: ; preds = %14
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %8
br label %52
34: ; preds = %22
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 4
br i1 %36, label %37, label %51
37: ; preds = %34
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
%42 = sub nsw i32 0, %41
store i32 %42, i32* %6
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %7
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = call i32 @atoi(i8* %49)
store i32 %50, i32* %8
br label %51
51: ; preds = %37, %34
br label %52
52: ; preds = %51, %25
br label %53
53: ; preds = %52, %17
br label %54
54: ; preds = %53
%55 = load i32, i32* @SYS_tgkill
%56 = load i32, i32* %7
%57 = load i32, i32* %8
%58 = load i32, i32* %6
%59 = call i32 @syscall(i32 %55, i32 %56, i32 %57, i32 %58)
store i32 %59, i32* %3
br label %60
60: ; preds = %54, %12
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@.str = [45 x i8] c"Usage: %s [-SIGNUM] [<tgid>] <tid>\0A, argv[0]\00"
@SYS_tgkill = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @SIGTERM
switch i32 %0, label %11 [
i32 1, label %4
i32 2, label %19
i32 3, label %12
i32 4, label %6
]
4: ; preds = %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %28
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = sub nsw i32 0, %9
br label %12
11: ; preds = %2
unreachable
12: ; preds = %2, %6
%13 = phi i64 [ 2, %6 ], [ 1, %2 ]
%14 = phi i64 [ 3, %6 ], [ 2, %2 ]
%15 = phi i32 [ %10, %6 ], [ %3, %2 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %13
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
br label %19
19: ; preds = %12, %2
%20 = phi i64 [ 1, %2 ], [ %14, %12 ]
%21 = phi i32 [ %3, %2 ], [ %15, %12 ]
%22 = phi i32 [ -1, %2 ], [ %18, %12 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 %20
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = load i32, i32* @SYS_tgkill
%27 = tail call i32 @syscall(i32 %26, i32 %22, i32 %25, i32 %21)
br label %28
28: ; preds = %19, %4
%29 = phi i32 [ 1, %4 ], [ %27, %19 ]
ret i32 %29
}