#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 */
struct in_addr {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
struct in_addr *calloc(int, int);
scalar_t__ check_hostname(char *, struct in_addr *);
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 getpid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int interval;
  char *command;
  struct in_addr *ips;
  FILE *pidfd;
  if (argc < 5)
    usage();
  interval = atoi(argv[2]);
  if (interval < 1) {
    fprintf(stderr, "Invalid interval %d\n", interval);
    exit(3);
  }
  command = argv[3];
  ips = calloc(argc - 4, sizeof(struct in_addr));
  if (ips == NULL) {
    fprintf(stderr, "calloc failed\n");
    exit(2);
  }
  if (daemon(0, 0) == -1)
    exit(1);
  pidfd = fopen(argv[1], "w");
  if (pidfd) {
    fprintf(pidfd, "%d\n", getpid());
    fclose(pidfd);
  }
  while (1) {
    int i;
    int changes = 0;
    for (i = 4; i < argc; i++)
      changes += check_hostname(argv[i], &ips[i - 4]);
    if (changes > 0)
      system(command);
    sleep(interval);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11e7 <main+0x27>
mov    $0x0,%al
call   1090 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1226 <main+0x66>
mov    0x2dd8(%rip),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%edx
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x4,%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1273 <main+0xb3>
mov    0x2d88(%rip),%rax
mov    (%rax),%rdi
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1080 <daemon@plt>
cmp    $0xffffffff,%eax
jne    128f <main+0xcf>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd86(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12de <main+0x11e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
jmp    12e3 <main+0x123>
movl   $0x0,-0x38(%rbp)
movl   $0x4,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    133c <main+0x17c>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%eax
sub    $0x4,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
call   10b0 <check_hostname@plt>
mov    %rax,%rcx
movslq -0x38(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12f1 <main+0x131>
cmpl   $0x0,-0x38(%rbp)
jle    134f <main+0x18f>
mov    -0x20(%rbp),%rdi
call   1050 <system@plt>
mov    -0x14(%rbp),%edi
call   10e0 <sleep@plt>
jmp    12e3 <main+0x123>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    %edi,%r12d
cmp    $0x4,%edi
jg     11f0 <main+0x20>
xor    %eax,%eax
call   1090 <usage@plt>
mov    0x10(%r13),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
test   %eax,%eax
jle    12e0 <main+0x110>
mov    0x18(%r13),%rax
mov    %rax,0x10(%rsp)
lea    -0x4(%r12),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
test   %rax,%rax
je     1305 <main+0x135>
mov    %rax,%rbp
xor    %edi,%edi
xor    %esi,%esi
call   1080 <daemon@plt>
cmp    $0xffffffff,%eax
je     132f <main+0x15f>
mov    0x8(%r13),%rdi
lea    0xddf(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1274 <main+0xa4>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdb1(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12d,%eax
lea    -0x10(,%rax,4),%rbx
ff
mov    %r15d,0xc(%rsp)
jmp    1298 <main+0xc8>
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%edi
call   10f0 <sleep@plt>
cmp    $0x5,%r12d
jl     1290 <main+0xc0>
xor    %r15d,%r15d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x20(%r13,%r15,2),%rdi
lea    (%r15,%rbp,1),%rsi
call   10b0 <check_hostname@plt>
add    %eax,%r14d
add    $0x4,%r15
cmp    %r15,%rbx
jne    12b0 <main+0xe0>
test   %r14d,%r14d
mov    0xc(%rsp),%r15d
jle    1290 <main+0xc0>
mov    0x10(%rsp),%rdi
call   1050 <system@plt>
jmp    1290 <main+0xc0>
mov    0x2cf9(%rip),%rax
mov    (%rax),%rdi
lea    0xd0f(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%rcx
lea    0xcff(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
@stderr = global i32* null
@.str = [21 x i8] c"Invalid interval %d\0A\00"
@.str.1 = [15 x i8] c"calloc failed\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [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 i8*
%8 = alloca %struct.in_addr*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 5
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (...) @usage()
br label %16
16: ; preds = %14, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %28
23: ; preds = %16
%24 = load i32*, i32** @stderr
%25 = load i32, i32* %6
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = call i32 @exit(i32 3)
unreachable
28: ; preds = %16
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
store i8* %31, i8** %7
%32 = load i32, i32* %4
%33 = sub nsw i32 %32, 4
%34 = call %struct.in_addr* @calloc(i32 %33, i32 4)
store %struct.in_addr* %34, %struct.in_addr** %8
%35 = load %struct.in_addr*, %struct.in_addr** %8
%36 = icmp eq %struct.in_addr* %35, null
br i1 %36, label %37, label %41
37: ; preds = %28
%38 = load i32*, i32** @stderr
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 2)
unreachable
41: ; preds = %28
%42 = call i32 @daemon(i32 0, i32 0)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %41
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %50, i32** %9
%51 = load i32*, i32** %9
%52 = icmp ne i32* %51, null
br i1 %52, label %53, label %59
53: ; preds = %46
%54 = load i32*, i32** %9
%55 = call i32 (...) @getpid()
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %55)
%57 = load i32*, i32** %9
%58 = call i32 @fclose(i32* %57)
br label %59
59: ; preds = %53, %46
br label %60
60: ; preds = %59, %90
store i32 0, i32* %11
store i32 4, i32* %10
br label %61
61: ; preds = %81, %60
%62 = load i32, i32* %10
%63 = load i32, i32* %4
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %84
65: ; preds = %61
%66 = load i8**, i8*** %5
%67 = load i32, i32* %10
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %66, i64 %68
%70 = load i8*, i8** %69
%71 = load %struct.in_addr*, %struct.in_addr** %8
%72 = load i32, i32* %10
%73 = sub nsw i32 %72, 4
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %71, i64 %74
%76 = call i64 @check_hostname(i8* %70, %struct.in_addr* %75)
%77 = load i32, i32* %11
%78 = sext i32 %77 to i64
%79 = add nsw i64 %78, %76
%80 = trunc i64 %79 to i32
store i32 %80, i32* %11
br label %81
81: ; preds = %65
%82 = load i32, i32* %10
%83 = add nsw i32 %82, 1
store i32 %83, i32* %10
br label %61
84: ; preds = %61
%85 = load i32, i32* %11
%86 = icmp sgt i32 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %84
%88 = load i8*, i8** %7
%89 = call i32 @system(i8* %88)
br label %90
90: ; preds = %87, %84
%91 = load i32, i32* %6
%92 = call i32 @sleep(i32 %91)
br label %60
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@stderr = global i32* null
@.str = [21 x i8] c"Invalid interval %d\0A\00"
@.str.1 = [15 x i8] c"calloc failed\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 5
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = load i32*, i32** @stderr
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %9)
%14 = tail call i32 @exit(i32 3)
unreachable
15: ; preds = %6
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = add nsw i32 %0, -4
%19 = tail call %struct.in_addr* @calloc(i32 %18, i32 4)
%20 = icmp eq %struct.in_addr* %19, null
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32*, i32** @stderr
%23 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i64 14, i64 1, i32* %22)
%24 = tail call i32 @exit(i32 2)
unreachable
25: ; preds = %15
%26 = tail call i32 @daemon(i32 0, i32 0)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %25
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = tail call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %39, label %35
35: ; preds = %30
%36 = tail call i32 (...) @getpid()
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = tail call i32 @fclose(i32* %33)
br label %39
39: ; preds = %35, %30
%40 = icmp sgt i32 %0, 4
%41 = zext i32 %0 to i64
br label %42
42: ; preds = %59, %39
br i1 %40, label %43, label %59
43: ; preds = %42, %43
%44 = phi i64 [ %53, %43 ], [ 4, %42 ]
%45 = phi i32 [ %52, %43 ], [ 0, %42 ]
%46 = getelementptr inbounds i8*, i8** %1, i64 %44
%47 = load i8*, i8** %46
%48 = add nsw i64 %44, -4
%49 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %19, i64 %48
%50 = tail call i64 @check_hostname(i8* %47, %struct.in_addr* %49)
%51 = trunc i64 %50 to i32
%52 = add i32 %45, %51
%53 = add nuw nsw i64 %44, 1
%54 = icmp eq i64 %53, %41
br i1 %54, label %55, label %43
55: ; preds = %43
%56 = icmp sgt i32 %52, 0
br i1 %56, label %57, label %59
57: ; preds = %55
%58 = tail call i32 @system(i8* %17)
br label %59
59: ; preds = %42, %57, %55
%60 = tail call i32 @sleep(i32 %9)
br label %42
}