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

/* Variables and functions */
scalar_t__ adddata_tokernel(char *, int);
int /*<<< orphan*/ do_system(char *, int);
int getpid();
int /*<<< orphan*/ init_netprobe_netlink();
int /*<<< orphan*/ init_signals();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int main() {
  char tmpbuf[16] = {0};
  static int countFlag = 0;
  do_system("/etc/init.d/dnsmasq restart", 1);
  init_signals();
  init_netprobe_netlink();
  memset(tmpbuf, 0, sizeof(tmpbuf));
  sprintf(tmpbuf, "%d", getpid());
  if (adddata_tokernel(tmpbuf, sizeof(tmpbuf)) != 0)
    printf("set pid to kernel fail !");
  while (1) {
    if (countFlag < 3) {
      memset(tmpbuf, 0, sizeof(tmpbuf));
      sprintf(tmpbuf, "%d", getpid());
      if (adddata_tokernel(tmpbuf, sizeof(tmpbuf)) != 0)
        printf("set pid to kernel fail !");
    }
    countFlag += 1;
    sleep(300);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0xe4a(%rip),%rdi
mov    $0x1,%esi
call   1070 <do_system@plt>
mov    $0x0,%al
call   1040 <init_signals@plt>
mov    $0x0,%al
call   1080 <init_netprobe_netlink@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe22(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
call   10b0 <adddata_tokernel@plt>
cmp    $0x0,%rax
je     1223 <main+0x93>
lea    0xe01(%rip),%rdi
call   1050 <printf@plt>
jmp    1228 <main+0x98>
cmpl   $0x3,0x2e3d(%rip)
jge    128f <main+0xff>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xdbb(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
call   10b0 <adddata_tokernel@plt>
cmp    $0x0,%rax
je     128a <main+0xfa>
lea    0xd9a(%rip),%rdi
call   1050 <printf@plt>
jmp    128f <main+0xff>
mov    0x2dd7(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2dce(%rip)
mov    $0x12c,%edi
call   10a0 <sleep@plt>
jmp    1228 <main+0x98>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0xe59(%rip),%rdi
mov    $0x1,%esi
call   1070 <do_system@plt>
xor    %eax,%eax
call   1040 <init_signals@plt>
xor    %eax,%eax
call   1080 <init_netprobe_netlink@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
call   10b0 <adddata_tokernel@plt>
test   %rax,%rax
je     1207 <main+0x77>
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
mov    %rsp,%rbx
lea    0xe0b(%rip),%r14
lea    0xe07(%rip),%r15
jmp    1231 <main+0xa1>
nopw   0x0(%rax,%rax,1)
addl   $0x1,0x2e45(%rip)
mov    $0x12c,%edi
call   10a0 <sleep@plt>
cmpl   $0x2,0x2e34(%rip)
jg     1220 <main+0x90>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
call   10b0 <adddata_tokernel@plt>
test   %rax,%rax
je     1220 <main+0x90>
mov    %r15,%rdi
call   1050 <printf@plt>
jmp    1220 <main+0x90>

LLVM IR (-O0):
@main.countFlag = internal global i32 0
@.str = [28 x i8] c"/etc/init.d/dnsmasq restart\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"set pid to kernel fail !\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
store i32 0, i32* %1
%3 = bitcast [16 x i8]* %2 to i8*
%4 = call i32 @do_system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 1)
%5 = call i32 (...) @init_signals()
%6 = call i32 (...) @init_netprobe_netlink()
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 16)
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%10 = call i32 (...) @getpid()
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%13 = call i64 @adddata_tokernel(i8* %12, i32 16)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
br label %18
18: ; preds = %17, %33
%19 = load i32, i32* @main.countFlag
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 16)
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%25 = call i32 (...) @getpid()
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%28 = call i64 @adddata_tokernel(i8* %27, i32 16)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %21
br label %33
33: ; preds = %32, %18
%34 = load i32, i32* @main.countFlag
%35 = add nsw i32 %34, 1
store i32 %35, i32* @main.countFlag
%36 = call i32 @sleep(i32 300)
br label %18
}

LLVM IR (-O2):
@main.countFlag = internal unnamed_addr global i32 0
@.str = [28 x i8] c"/etc/init.d/dnsmasq restart\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [25 x i8] c"set pid to kernel fail !\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @do_system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 1)
%4 = tail call i32 (...) @init_signals()
%5 = tail call i32 (...) @init_netprobe_netlink()
%6 = call i32 @memset(i8* %2, i32 0, i32 16)
%7 = call i32 (...) @getpid()
%8 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i64 @adddata_tokernel(i8* %2, i32 16)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %0
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
br label %14
14: ; preds = %13, %25
%15 = load i32, i32* @main.countFlag
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = call i32 @memset(i8* %2, i32 0, i32 16)
%19 = call i32 (...) @getpid()
%20 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i64 @adddata_tokernel(i8* %2, i32 16)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %17
%24 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %17, %23, %14
%26 = load i32, i32* @main.countFlag
%27 = add nsw i32 %26, 1
store i32 %27, i32* @main.countFlag
%28 = call i32 @sleep(i32 300)
br label %14
}