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

/* Variables and functions */
int atoi(char *);
int daemon(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getpid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unsetenv(char *);
int main(int argc, char *argv[]) {
  int interval;
  FILE *pidfd;
  if (argc < 4)
    exit(1);
  interval = atoi(argv[1]);
  if (interval == 0)
    exit(1);
  unsetenv("CONTENT_TYPE");
  unsetenv("GATEWAY_INTERFACE");
  unsetenv("REMOTE_USER");
  unsetenv("REMOTE_ADDR");
  unsetenv("AUTH_TYPE");
  unsetenv("SCRIPT_FILENAME");
  unsetenv("CONTENT_LENGTH");
  unsetenv("HTTP_USER_AGENT");
  unsetenv("HTTP_HOST");
  unsetenv("SERVER_SOFTWARE");
  unsetenv("HTTP_REFERER");
  unsetenv("SERVER_PROTOCOL");
  unsetenv("REQUEST_METHOD");
  unsetenv("SERVER_PORT");
  unsetenv("SCRIPT_NAME");
  unsetenv("SERVER_NAME");
  if (daemon(0, 0) == -1)
    exit(1);
  pidfd = fopen(argv[2], "w");
  if (pidfd) {
    fprintf(pidfd, "%d\n", getpid());
    fclose(pidfd);
  }
  while (1) {
    sleep(interval);
    system(argv[3]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11ca <main+0x2a>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ee <main+0x4e>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xe0b(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe0c(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe12(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe12(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe12(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe10(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe14(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe17(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe1b(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe19(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe1d(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe1e(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe22(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe25(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe25(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe25(%rip),%rdi
call   1090 <unsetenv@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1070 <daemon@plt>
cmp    $0xffffffff,%eax
jne    12ca <main+0x12a>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe01(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1317 <main+0x177>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xdd3(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    131c <main+0x17c>
mov    -0x14(%rbp),%edi
call   10c0 <sleep@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1050 <system@plt>
jmp    131c <main+0x17c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
jle    12e2 <main+0x142>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
je     12e2 <main+0x142>
mov    %eax,%ebp
lea    0xe36(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe37(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe3d(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe3d(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe3d(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe3b(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe3f(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe42(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe46(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe44(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe48(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe49(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe4d(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe50(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe50(%rip),%rdi
call   1090 <unsetenv@plt>
lea    0xe50(%rip),%rdi
call   1090 <unsetenv@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1070 <daemon@plt>
cmp    $0xffffffff,%eax
je     12e2 <main+0x142>
mov    0x10(%rbx),%rdi
lea    0xe3e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12d0 <main+0x130>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe25(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
nopl   0x0(%rax)
mov    %ebp,%edi
call   10c0 <sleep@plt>
mov    0x18(%rbx),%rdi
call   1050 <system@plt>
jmp    12d0 <main+0x130>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"CONTENT_TYPE\00"
@.str.1 = [18 x i8] c"GATEWAY_INTERFACE\00"
@.str.2 = [12 x i8] c"REMOTE_USER\00"
@.str.3 = [12 x i8] c"REMOTE_ADDR\00"
@.str.4 = [10 x i8] c"AUTH_TYPE\00"
@.str.5 = [16 x i8] c"SCRIPT_FILENAME\00"
@.str.6 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.7 = [16 x i8] c"HTTP_USER_AGENT\00"
@.str.8 = [10 x i8] c"HTTP_HOST\00"
@.str.9 = [16 x i8] c"SERVER_SOFTWARE\00"
@.str.10 = [13 x i8] c"HTTP_REFERER\00"
@.str.11 = [16 x i8] c"SERVER_PROTOCOL\00"
@.str.12 = [15 x i8] c"REQUEST_METHOD\00"
@.str.13 = [12 x i8] c"SERVER_PORT\00"
@.str.14 = [12 x i8] c"SCRIPT_NAME\00"
@.str.15 = [12 x i8] c"SERVER_NAME\00"
@.str.16 = [2 x i8] c"w\00"
@.str.17 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = call i32 @unsetenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @unsetenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @unsetenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%28 = call i32 @unsetenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%29 = call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%30 = call i32 @unsetenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%31 = call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%32 = call i32 @unsetenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%33 = call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%34 = call i32 @unsetenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
%35 = call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0))
%36 = call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
%37 = call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%38 = call i32 @daemon(i32 0, i32 0)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %21
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %21
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0))
store i32* %46, i32** %7
%47 = load i32*, i32** %7
%48 = icmp ne i32* %47, null
br i1 %48, label %49, label %55
49: ; preds = %42
%50 = load i32*, i32** %7
%51 = call i32 (...) @getpid()
%52 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i64 0, i64 0), i32 %51)
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
br label %55
55: ; preds = %49, %42
br label %56
56: ; preds = %55, %56
%57 = load i32, i32* %6
%58 = call i32 @sleep(i32 %57)
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 3
%61 = load i8*, i8** %60
%62 = call i32 @system(i8* %61)
br label %56
}

LLVM IR (-O2):
@.str = [13 x i8] c"CONTENT_TYPE\00"
@.str.1 = [18 x i8] c"GATEWAY_INTERFACE\00"
@.str.2 = [12 x i8] c"REMOTE_USER\00"
@.str.3 = [12 x i8] c"REMOTE_ADDR\00"
@.str.4 = [10 x i8] c"AUTH_TYPE\00"
@.str.5 = [16 x i8] c"SCRIPT_FILENAME\00"
@.str.6 = [15 x i8] c"CONTENT_LENGTH\00"
@.str.7 = [16 x i8] c"HTTP_USER_AGENT\00"
@.str.8 = [10 x i8] c"HTTP_HOST\00"
@.str.9 = [16 x i8] c"SERVER_SOFTWARE\00"
@.str.10 = [13 x i8] c"HTTP_REFERER\00"
@.str.11 = [16 x i8] c"SERVER_PROTOCOL\00"
@.str.12 = [15 x i8] c"REQUEST_METHOD\00"
@.str.13 = [12 x i8] c"SERVER_PORT\00"
@.str.14 = [12 x i8] c"SCRIPT_NAME\00"
@.str.15 = [12 x i8] c"SERVER_NAME\00"
@.str.16 = [2 x i8] c"w\00"
@.str.17 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %6
%14 = tail call i32 @unsetenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @unsetenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @unsetenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%19 = tail call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%20 = tail call i32 @unsetenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%21 = tail call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%22 = tail call i32 @unsetenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%23 = tail call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%24 = tail call i32 @unsetenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%25 = tail call i32 @unsetenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%26 = tail call i32 @unsetenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
%27 = tail call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0))
%28 = tail call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
%29 = tail call i32 @unsetenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
%30 = tail call i32 @daemon(i32 0, i32 0)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %13
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %13
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = tail call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0))
%38 = icmp eq i32* %37, null
br i1 %38, label %43, label %39
39: ; preds = %34
%40 = tail call i32 (...) @getpid()
%41 = tail call i32 @fprintf(i32* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.17, i64 0, i64 0), i32 %40)
%42 = tail call i32 @fclose(i32* %37)
br label %43
43: ; preds = %39, %34
%44 = getelementptr inbounds i8*, i8** %1, i64 3
br label %45
45: ; preds = %45, %43
%46 = tail call i32 @sleep(i32 %9)
%47 = load i8*, i8** %44
%48 = tail call i32 @system(i8* %47)
br label %45
}