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

/* Variables and functions */
int /*<<< orphan*/ SIGTERM;
scalar_t__ find_pid_by_name(char *, int /*<<< orphan*/ *, int);
int kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ system(char *);
void wdctl_restart(void) {
  pid_t pid;
  if (find_pid_by_name("wifidog", &pid, 1) > 0) {
    kill(pid, SIGTERM);
    while (kill(pid, 0) != -1) {
      sleep(1);
    }
    system("wifidog");
  }
}


x86 assembly (clang, -O0):
<wdctl_restart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x1,%edx
call   1040 <find_pid_by_name@plt>
cmp    $0x0,%rax
jle    11a6 <wdctl_restart+0x66>
mov    -0x4(%rbp),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1050 <kill@plt>
cmp    $0xffffffff,%eax
je     119a <wdctl_restart+0x5a>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    1178 <wdctl_restart+0x38>
lea    0xe5f(%rip),%rdi
call   1030 <system@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wdctl_restart>:
push   %rax
lea    0xeb8(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    $0x1,%edx
call   1040 <find_pid_by_name@plt>
test   %rax,%rax
jle    1198 <wdctl_restart+0x58>
mov    0x4(%rsp),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1050 <kill@plt>
xchg   %ax,%ax
mov    0x4(%rsp),%edi
xor    %esi,%esi
call   1050 <kill@plt>
cmp    $0xffffffff,%eax
je     118c <wdctl_restart+0x4c>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    1170 <wdctl_restart+0x30>
lea    0xe6d(%rip),%rdi
call   1030 <system@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [8 x i8] c"wifidog\00"
@SIGTERM = global i32 0
define void @wdctl_restart() {
%1 = alloca i32
%2 = call i64 @find_pid_by_name(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %1, i32 1)
%3 = icmp sgt i64 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %0
%5 = load i32, i32* %1
%6 = load i32, i32* @SIGTERM
%7 = call i32 @kill(i32 %5, i32 %6)
br label %8
8: ; preds = %12, %4
%9 = load i32, i32* %1
%10 = call i32 @kill(i32 %9, i32 0)
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @sleep(i32 1)
br label %8
14: ; preds = %8
%15 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"wifidog\00"
@SIGTERM = global i32 0
define void @wdctl_restart() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @find_pid_by_name(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32* %1, i32 1)
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %0
%6 = load i32, i32* %1
%7 = load i32, i32* @SIGTERM
%8 = call i32 @kill(i32 %6, i32 %7)
%9 = load i32, i32* %1
%10 = call i32 @kill(i32 %9, i32 0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %17, label %12
12: ; preds = %5, %12
%13 = call i32 @sleep(i32 1)
%14 = load i32, i32* %1
%15 = call i32 @kill(i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %12
17: ; preds = %12, %5
%18 = call i32 @system(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %0
ret void
}