#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_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ errno;
scalar_t__ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, scalar_t__ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid, pid_kill;
  int child_status;
  char *user_name;
  if ((user_name = getenv("USER")) == NULL) {
    fprintf(stderr, "Err.(%s) getenv() failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  char *arg_var[] = {"ps",     "-U", user_name, "-o", "pid,ppid,ruid,euid,args",
                     (char *)0};
  if ((pid = fork()) < 0) {
    fprintf(stderr, "Err.(%s) fork() failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    if (execv("/bin/ps", arg_var) < 0) {
      fprintf(stderr, "Err.(%s) fork() failed\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
  } else {
    if (waitpid(-1, &child_status, 0) < 0) {
      fprintf(stderr, "Err.(%s) waitpid() failed\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
    printf("get PID to kill (0=quit): ");
    scanf("%d", &pid_kill);
    if (pid_kill == 0) {
      printf("bye\n");
      exit(0);
    }
    if (kill(pid_kill, SIGKILL) == -1) {
      fprintf(stderr, "Err.(%s) fork() failed\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe40(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    120d <main+0x6d>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xe0b(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xe46(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xe00(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
lea    0xdf0(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xde8(%rip),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1298 <main+0xf8>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xdb8(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    12fc <main+0x15c>
lea    -0x60(%rbp),%rsi
lea    0xda7(%rip),%rdi
call   10b0 <execv@plt>
cmp    $0x0,%rax
jge    12f7 <main+0x157>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xd59(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    13e4 <main+0x244>
mov    $0xffffffff,%edi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0x0,%rax
jge    1350 <main+0x1b0>
mov    0x2cc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x70(%rbp),%edi
mov    %rax,%rdx
lea    0xd20(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xd21(%rip),%rdi
call   1040 <printf@plt>
lea    0xd30(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <scanf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    138a <main+0x1ea>
lea    0xd18(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2c33(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
cmp    $0xffffffff,%eax
jne    13df <main+0x23f>
mov    0x2c34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2c20(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xc71(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2bf8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    13e4 <main+0x244>
jmp    13e9 <main+0x249>
mov    0x2bd0(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0xe44(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12b0 <main+0x100>
lea    0xe89(%rip),%rcx
mov    %rcx,0x10(%rsp)
lea    0xe42(%rip),%rcx
mov    %rcx,0x18(%rsp)
mov    %rax,0x20(%rsp)
lea    0xe34(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe2b(%rip),%rax
mov    %rax,0x30(%rsp)
movq   $0x0,0x38(%rsp)
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
js     1290 <main+0xe0>
je     127a <main+0xca>
lea    0xc(%rsp),%rsi
mov    $0xffffffff,%edi
xor    %edx,%edx
call   1090 <waitpid@plt>
test   %rax,%rax
js     12d0 <main+0x120>
lea    0xe41(%rip),%rdi
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
mov    %rsp,%rsi
call   1080 <scanf@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1306 <main+0x156>
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
cmp    $0xffffffff,%eax
je     1290 <main+0xe0>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbx
ret
lea    0xdd4(%rip),%rdi
lea    0x10(%rsp),%rsi
call   10c0 <execv@plt>
test   %rax,%rax
jns    126b <main+0xbb>
mov    0x2d49(%rip),%rax
mov    (%rax),%ebx
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd8f(%rip),%rsi
jmp    12ee <main+0x13e>
mov    0x2d29(%rip),%rax
mov    (%rax),%ebx
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd37(%rip),%rsi
jmp    12ee <main+0x13e>
mov    0x2d09(%rip),%rax
mov    (%rax),%ebx
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd6f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xd89(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"USER\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Err.(%s) getenv() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"ps\00"
@.str.3 = [3 x i8] c"-U\00"
@.str.4 = [3 x i8] c"-o\00"
@.str.5 = [24 x i8] c"pid,ppid,ruid,euid,args\00"
@.str.6 = [24 x i8] c"Err.(%s) fork() failed\0A\00"
@.str.7 = [8 x i8] c"/bin/ps\00"
@.str.8 = [27 x i8] c"Err.(%s) waitpid() failed\0A\00"
@.str.9 = [27 x i8] c"get PID to kill (0=quit): \00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [5 x i8] c"bye\0A\00"
@SIGKILL = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [6 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %9
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds [6 x i8*], [6 x i8*]* %10, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %9
store i8* %24, i8** %23
%25 = getelementptr inbounds i8*, i8** %23, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %25
%26 = getelementptr inbounds i8*, i8** %25, i64 1
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8** %26
%27 = getelementptr inbounds i8*, i8** %26, i64 1
store i8* null, i8** %27
%28 = call i64 (...) @fork()
store i64 %28, i64* %6
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %20
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %20
%38 = load i64, i64* %6
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %52
40: ; preds = %37
%41 = getelementptr inbounds [6 x i8*], [6 x i8*]* %10, i64 0, i64 0
%42 = call i64 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8** %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %40
br label %83
52: ; preds = %37
%53 = call i64 @waitpid(i32 -1, i32* %8, i32 0)
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %52
%63 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%64 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i64* %7)
%65 = load i64, i64* %7
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %62
%68 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%69 = call i32 @exit(i32 0)
unreachable
70: ; preds = %62
%71 = load i64, i64* %7
%72 = load i32, i32* @SIGKILL
%73 = call i32 @kill(i64 %71, i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %82
75: ; preds = %70
%76 = load i32, i32* @stderr
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %78)
%80 = load i32, i32* @EXIT_FAILURE
%81 = call i32 @exit(i32 %80)
unreachable
82: ; preds = %70
br label %83
83: ; preds = %82, %51
br label %84
84: ; preds = %83
%85 = load i32, i32* @EXIT_SUCCESS
ret i32 %85
}

LLVM IR (-O2):
@.str = [5 x i8] c"USER\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"Err.(%s) getenv() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"ps\00"
@.str.3 = [3 x i8] c"-U\00"
@.str.4 = [3 x i8] c"-o\00"
@.str.5 = [24 x i8] c"pid,ppid,ruid,euid,args\00"
@.str.6 = [24 x i8] c"Err.(%s) fork() failed\0A\00"
@.str.7 = [8 x i8] c"/bin/ps\00"
@.str.8 = [27 x i8] c"Err.(%s) waitpid() failed\0A\00"
@.str.9 = [27 x i8] c"get PID to kill (0=quit): \00"
@.str.10 = [3 x i8] c"%d\00"
@SIGKILL = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [4 x i8] c"bye\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca [6 x i8*]
%6 = bitcast i64* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = bitcast [6 x i8*]* %5 to i8*
%19 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %19
%20 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 2
store i8* %8, i8** %21
%22 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 4
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 5
store i8* null, i8** %24
%25 = tail call i64 (...) @fork()
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %17
%35 = icmp eq i64 %25, 0
br i1 %35, label %36, label %46
36: ; preds = %34
%37 = call i64 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8** %19)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %75
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %34
%47 = call i64 @waitpid(i32 -1, i32* %4, i32 0)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %56
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %46
%57 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%58 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i64* %3)
%59 = load i64, i64* %3
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%63 = call i32 @exit(i32 0)
unreachable
64: ; preds = %56
%65 = load i32, i32* @SIGKILL
%66 = call i32 @kill(i64 %59, i32 %65)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %75
68: ; preds = %64
%69 = load i32, i32* @stderr
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %71)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %36, %64
%76 = load i32, i32* @EXIT_SUCCESS
ret i32 %76
}