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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, int *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unlink(char *);
int main() {
  int fd = open("id", O_RDONLY);
  if (fd == -1)
    return 0;
  char cmd[100];
  pid_t id;
  while (read(fd, &id, sizeof(id)) == sizeof(id)) {
    sprintf(cmd, "kill %d", id);
    system(cmd);
  }
  close(fd);
  unlink("id");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0xe7e(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11a0 <main+0x40>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <main+0x97>
jmp    11a5 <main+0x45>
mov    -0x8(%rbp),%edi
lea    -0x74(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cltq
cmp    $0x4,%rax
jne    11e3 <main+0x83>
lea    -0x70(%rbp),%rdi
mov    -0x74(%rbp),%edx
lea    0xe33(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <system@plt>
jmp    11a5 <main+0x45>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
lea    0xe0e(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
lea    0xe86(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11ee <main+0x8e>
mov    %eax,%ebp
lea    0xc(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
jne    11db <main+0x7b>
lea    0xe60(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r15
nopl   (%rax)
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
je     11b0 <main+0x50>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe17(%rip),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"id\00"
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"kill %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 0, i32* %1
br label %26
10: ; preds = %0
br label %11
11: ; preds = %16, %10
%12 = load i32, i32* %2
%13 = call i32 @read(i32 %12, i32* %4, i32 4)
%14 = sext i32 %13 to i64
%15 = icmp eq i64 %14, 4
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%21 = call i32 @system(i8* %20)
br label %11
22: ; preds = %11
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
%25 = call i32 @unlink(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %22, %9
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [3 x i8] c"id\00"
@O_RDONLY = global i32 0
@.str.1 = [8 x i8] c"kill %d\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %20, label %6
6: ; preds = %0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%8 = bitcast i32* %2 to i8*
%9 = call i32 @read(i32 %4, i32* %2, i32 4)
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %17
11: ; preds = %6, %11
%12 = load i32, i32* %2
%13 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i32 @system(i8* %7)
%15 = call i32 @read(i32 %4, i32* %2, i32 4)
%16 = icmp eq i32 %15, 4
br i1 %16, label %11, label %17
17: ; preds = %11, %6
%18 = tail call i32 @close(i32 %4)
%19 = tail call i32 @unlink(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %0, %17
ret i32 0
}