#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ getppid();
int /*<<< orphan*/ kill(scalar_t__, int);
int /*<<< orphan*/ printf(char *, char *, scalar_t__);
int main(int argc, char **argv) {
  pid_t pid;
  char *tgt = "child";
  pid = fork();
  if (pid == 0) {
    pid = getppid();
    tgt = "parent";
  }
  kill(pid, 9);
  printf("Sent SIGKILL to %s:%d\n", tgt, pid);
  exit(0);
}


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)
lea    0xe93(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119d <main+0x4d>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %rax,-0x18(%rbp)
lea    0xe6d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x9,%esi
call   1040 <kill@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    1173 <main+0x23>
xor    %eax,%eax
call   1050 <getppid@plt>
mov    %rax,%rbx
lea    0xe95(%rip),%r14
jmp    117d <main+0x2d>
mov    %rax,%rbx
lea    0xe83(%rip),%r14
mov    %rbx,%rdi
mov    $0x9,%esi
call   1040 <kill@plt>
lea    0xe7c(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"child\00"
@.str.1 = [7 x i8] c"parent\00"
@.str.2 = [23 x i8] c"Sent SIGKILL to %s:%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i64 (...) @getppid()
store i64 %12, i64* %6
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %13
13: ; preds = %11, %2
%14 = load i64, i64* %6
%15 = call i32 @kill(i64 %14, i32 9)
%16 = load i8*, i8** %7
%17 = load i64, i64* %6
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %16, i64 %17)
%19 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"child\00"
@.str.1 = [7 x i8] c"parent\00"
@.str.2 = [23 x i8] c"Sent SIGKILL to %s:%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i64 (...) @getppid()
br label %7
7: ; preds = %5, %2
%8 = phi i64 [ %6, %5 ], [ %3, %2 ]
%9 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %2 ]
%10 = tail call i32 @kill(i64 %8, i32 9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %9, i64 %8)
%12 = tail call i32 @exit(i32 0)
unreachable
}