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

/* Variables and functions */
int /*<<< orphan*/ WNOHANG;
int atoi(char *);
scalar_t__ fork();
int getopt(int, char **, char *);
int /*<<< orphan*/ kill(scalar_t__, int);
char *optarg;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, scalar_t__, int, int);
int /*<<< orphan*/ run_command(char *);
int /*<<< orphan*/ show_help();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int opt, fd, interval;
  char *fname = NULL;
  FILE *file = NULL;
  char *command = NULL;
  pid_t pid;
  int signal = 3;
  while ((opt = getopt(argc, argv, "t:f:c:s:h")) != -1) {
    switch (opt) {
    case 't':
      interval = atoi(optarg);
      break;
    case 'f':
      fname = optarg;
      break;
    case 'c':
      command = optarg;
      break;
    case 's':
      signal = atoi(optarg);
      break;
    case 'h':
    default:
      show_help();
      break;
    }
  }
  if ((pid = fork()) < 0) {
    perror("fork");
  } else if (pid == 0) {
    sleep(3);
    run_command(command);
  } else {
    printf("PID(%d) after %d seconds will recv %d signal\n", pid, interval,
           signal);
  }
  sleep(interval);
  kill(pid, signal);
  waitpid(pid, &opt, WNOHANG);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x3,-0x44(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1282 <main+0xe2>
mov    -0x14(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0x11,%eax
ja     1276 <main+0xd6>
mov    -0x50(%rbp),%rax
lea    0xdec(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2dd4(%rip),%rax
mov    (%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    127d <main+0xdd>
mov    0x2dbd(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    127d <main+0xdd>
mov    0x2daa(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    127d <main+0xdd>
mov    0x2d97(%rip),%rax
mov    (%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x44(%rbp)
jmp    127d <main+0xdd>
jmp    1276 <main+0xd6>
mov    $0x0,%al
call   1050 <show_help@plt>
jmp    11d5 <main+0x35>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jge    12a8 <main+0x108>
lea    0xdb4(%rip),%rdi
call   1080 <perror@plt>
jmp    12e6 <main+0x146>
cmpq   $0x0,-0x40(%rbp)
jne    12cb <main+0x12b>
mov    $0x3,%edi
call   10b0 <sleep@plt>
mov    -0x38(%rbp),%rdi
call   1060 <run_command@plt>
jmp    12e1 <main+0x141>
mov    -0x40(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x44(%rbp),%ecx
lea    0xd7b(%rip),%rdi
call   1030 <printf@plt>
jmp    12e6 <main+0x146>
mov    -0x1c(%rbp),%edi
call   10b0 <sleep@plt>
mov    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1040 <kill@plt>
mov    -0x40(%rbp),%rdi
mov    0x2cdb(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rsi
call   1070 <waitpid@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    $0x3,%r12d
lea    0xe88(%rip),%r13
lea    0xe39(%rip),%r14
mov    0x2e2a(%rip),%r15
xor    %eax,%eax
mov    %rax,0x10(%rsp)
jmp    11ec <main+0x4c>
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     122f <main+0x8f>
xor    %eax,%eax
call   1050 <show_help@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1090 <getopt@plt>
lea    -0x63(%rax),%ecx
cmp    $0x11,%ecx
ja     11e0 <main+0x40>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
jmp    11ec <main+0x4c>
mov    (%r15),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r12d
jmp    11ec <main+0x4c>
mov    (%r15),%rdi
call   10a0 <atoi@plt>
mov    %eax,0x8(%rsp)
jmp    11ec <main+0x4c>
movl   $0xffffffff,0xc(%rsp)
ff
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     12af <main+0x10f>
mov    0x8(%rsp),%ebp
je     1262 <main+0xc2>
lea    0xe04(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r12d,%ecx
call   1030 <printf@plt>
jmp    1276 <main+0xd6>
mov    $0x3,%edi
call   10b0 <sleep@plt>
mov    0x10(%rsp),%rdi
call   1060 <run_command@plt>
mov    %ebp,%edi
call   10b0 <sleep@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1040 <kill@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <waitpid@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9c(%rip),%rdi
call   1080 <perror@plt>
mov    0x8(%rsp),%ebp
jmp    1276 <main+0xd6>

LLVM IR (-O0):
@.str = [10 x i8] c"t:f:c:s:h\00"
@optarg = global i8* null
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [46 x i8] c"PID(%d) after %d seconds will recv %d signal\0A\00"
@WNOHANG = 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
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %9
store i32* null, i32** %10
store i8* null, i8** %11
store i32 3, i32* %13
br label %14
14: ; preds = %34, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %6
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %35
19: ; preds = %14
%20 = load i32, i32* %6
switch i32 %20, label %32 [
i32 116, label %21
i32 102, label %24
i32 99, label %26
i32 115, label %28
i32 104, label %31
]
21: ; preds = %19
%22 = load i8*, i8** @optarg
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8
br label %34
24: ; preds = %19
%25 = load i8*, i8** @optarg
store i8* %25, i8** %9
br label %34
26: ; preds = %19
%27 = load i8*, i8** @optarg
store i8* %27, i8** %11
br label %34
28: ; preds = %19
%29 = load i8*, i8** @optarg
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %13
br label %34
31: ; preds = %19
br label %32
32: ; preds = %19, %31
%33 = call i32 (...) @show_help()
br label %34
34: ; preds = %32, %28, %26, %24, %21
br label %14
35: ; preds = %14
%36 = call i64 (...) @fork()
store i64 %36, i64* %12
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %53
40: ; preds = %35
%41 = load i64, i64* %12
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = call i32 @sleep(i32 3)
%45 = load i8*, i8** %11
%46 = call i32 @run_command(i8* %45)
br label %52
47: ; preds = %40
%48 = load i64, i64* %12
%49 = load i32, i32* %8
%50 = load i32, i32* %13
%51 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 %48, i32 %49, i32 %50)
br label %52
52: ; preds = %47, %43
br label %53
53: ; preds = %52, %38
%54 = load i32, i32* %8
%55 = call i32 @sleep(i32 %54)
%56 = load i64, i64* %12
%57 = load i32, i32* %13
%58 = call i32 @kill(i64 %56, i32 %57)
%59 = load i64, i64* %12
%60 = load i32, i32* @WNOHANG
%61 = call i32 @waitpid(i64 %59, i32* %6, i32 %60)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"t:f:c:s:h\00"
@optarg = global i8* null
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [46 x i8] c"PID(%d) after %d seconds will recv %d signal\0A\00"
@WNOHANG = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %20, %2
%6 = phi i8* [ %21, %20 ], [ null, %2 ]
%7 = phi i32 [ %10, %20 ], [ undef, %2 ]
%8 = phi i32 [ %13, %20 ], [ 3, %2 ]
br label %9
9: ; preds = %5, %17
%10 = phi i32 [ %7, %5 ], [ %19, %17 ]
%11 = phi i32 [ %8, %5 ], [ %13, %17 ]
br label %12
12: ; preds = %9, %22
%13 = phi i32 [ %11, %9 ], [ %24, %22 ]
br label %14
14: ; preds = %16, %12
%15 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
switch i32 %15, label %25 [
i32 -1, label %27
i32 116, label %17
i32 102, label %16
i32 99, label %20
i32 115, label %22
]
16: ; preds = %14, %25
br label %14
17: ; preds = %14
%18 = load i8*, i8** @optarg
%19 = tail call i32 @atoi(i8* %18)
br label %9
20: ; preds = %14
%21 = load i8*, i8** @optarg
br label %5
22: ; preds = %14
%23 = load i8*, i8** @optarg
%24 = tail call i32 @atoi(i8* %23)
br label %12
25: ; preds = %14
%26 = tail call i32 (...) @show_help()
br label %16
27: ; preds = %14
store i32 -1, i32* %3
%28 = tail call i64 (...) @fork()
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %39
32: ; preds = %27
%33 = icmp eq i64 %28, 0
br i1 %33, label %34, label %37
34: ; preds = %32
%35 = tail call i32 @sleep(i32 3)
%36 = tail call i32 @run_command(i8* %6)
br label %39
37: ; preds = %32
%38 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 %28, i32 %10, i32 %13)
br label %39
39: ; preds = %34, %37, %30
%40 = tail call i32 @sleep(i32 %10)
%41 = tail call i32 @kill(i64 %28, i32 %13)
%42 = load i32, i32* @WNOHANG
%43 = call i32 @waitpid(i64 %28, i32* %3, i32 %42)
ret i32 0
}