#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;

/* Variables and functions */
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ execvp(char *, char **);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ pulse_led();
int /*<<< orphan*/ signal_and_wait(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stop_pulse(scalar_t__);
void do_ping(char *pingIP) {
  char *argv[] = {"ping", "-c 30", pingIP, NULL};
  pid_t ping_pid = fork();
  if (ping_pid == 0) {
    execvp(argv[0], argv);
    printf("Should never get here\n");
  }
  printf("Pinging on PID %d\n", ping_pid);
  pid_t pulse_pid = pulse_led();
  printf("Pulsing on PID %d\n", pulse_pid);
  sleep(5);
  signal_and_wait(ping_pid, SIGTERM);
  stop_pulse(pulse_pid);
}


x86 assembly (clang, -O0):
<do_ping>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11d3 <do_ping+0x63>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <execvp@plt>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <pulse_led@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    -0x38(%rbp),%rdi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
call   1060 <signal_and_wait@plt>
mov    -0x40(%rbp),%rdi
call   1040 <stop_pulse@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_ping>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xe72(%rip),%rax
mov    %rax,(%rsp)
lea    0xe6c(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %rdi,0x10(%rsp)
movq   $0x0,0x18(%rsp)
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11d6 <do_ping+0x56>
lea    0xe3e(%rip),%rdi
mov    %rsp,%rsi
call   1080 <execvp@plt>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <pulse_led@plt>
mov    %rax,%rbx
lea    0xe26(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x5,%edi
call   1090 <sleep@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <signal_and_wait@plt>
mov    %rbx,%rdi
call   1050 <stop_pulse@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"ping\00"
@.str.1 = [6 x i8] c"-c 30\00"
@.str.2 = [23 x i8] c"Should never get here\0A\00"
@.str.3 = [19 x i8] c"Pinging on PID %d\0A\00"
@.str.4 = [19 x i8] c"Pulsing on PID %d\0A\00"
@SIGTERM = global i32 0
define void @do_ping(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i8*]
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %2
%6 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds i8*, i8** %6, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %2
store i8* %9, i8** %8
%10 = getelementptr inbounds i8*, i8** %8, i64 1
store i8* null, i8** %10
%11 = call i64 (...) @fork()
store i64 %11, i64* %4
%12 = load i64, i64* %4
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %1
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%18 = call i32 @execvp(i8* %16, i8** %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %14, %1
%21 = load i64, i64* %4
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %21)
%23 = call i64 (...) @pulse_led()
store i64 %23, i64* %5
%24 = load i64, i64* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %24)
%26 = call i32 @sleep(i32 5)
%27 = load i64, i64* %4
%28 = load i32, i32* @SIGTERM
%29 = call i32 @signal_and_wait(i64 %27, i32 %28)
%30 = load i64, i64* %5
%31 = call i32 @stop_pulse(i64 %30)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"ping\00"
@.str.1 = [6 x i8] c"-c 30\00"
@.str.3 = [19 x i8] c"Pinging on PID %d\0A\00"
@.str.4 = [19 x i8] c"Pulsing on PID %d\0A\00"
@SIGTERM = global i32 0
@str = [22 x i8] c"Should never get here\00"
define void @do_ping(i8* %0) {
%2 = alloca [4 x i8*]
%3 = bitcast [4 x i8*]* %2 to i8*
%4 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 2
store i8* %0, i8** %6
%7 = getelementptr inbounds [4 x i8*], [4 x i8*]* %2, i64 0, i64 3
store i8* null, i8** %7
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @execvp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %8)
%15 = call i64 (...) @pulse_led()
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %15)
%17 = call i32 @sleep(i32 5)
%18 = load i32, i32* @SIGTERM
%19 = call i32 @signal_and_wait(i64 %8, i32 %18)
%20 = call i32 @stop_pulse(i64 %15)
ret void
}