#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*/ WNOHANG;
int /*<<< orphan*/ do_log(char *);
int /*<<< orphan*/ sprintf(char *, char *, scalar_t__);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void check_script(pid_t *pid) {
  int s;
  pid_t p;
  char m[30];
  if (*pid) {
    p = waitpid(*pid, &s, WNOHANG);
    if (p == *pid) {
      sprintf(m, "Script: [%d] exited", *pid);
      do_log(m);
      *pid = 0;
    }
  }
}


x86 assembly (clang, -O0):
<check_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a8 <check_script+0x78>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1040 <waitpid@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%rax
jne    11a3 <check_script+0x73>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <do_log@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
jmp    11a8 <check_script+0x78>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_script>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1180 <check_script+0x50>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
call   1040 <waitpid@plt>
cmp    (%rbx),%rax
jne    1180 <check_script+0x50>
lea    0xe9f(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rax,%rdx
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1030 <do_log@plt>
movq   $0x0,(%rbx)
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@WNOHANG = global i32 0
@.str = [20 x i8] c"Script: [%d] exited\00"
define void @check_script(i64* %0) {
%2 = alloca i64*
%3 = alloca i32
%4 = alloca i64
%5 = alloca [30 x i8]
store i64* %0, i64** %2
%6 = load i64*, i64** %2
%7 = load i64, i64* %6
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %1
%10 = load i64*, i64** %2
%11 = load i64, i64* %10
%12 = load i32, i32* @WNOHANG
%13 = call i64 @waitpid(i64 %11, i32* %3, i32 %12)
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = load i64*, i64** %2
%16 = load i64, i64* %15
%17 = icmp eq i64 %14, %16
br i1 %17, label %18, label %26
18: ; preds = %9
%19 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%20 = load i64*, i64** %2
%21 = load i64, i64* %20
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 %21)
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%24 = call i32 @do_log(i8* %23)
%25 = load i64*, i64** %2
store i64 0, i64* %25
br label %26
26: ; preds = %18, %9
br label %27
27: ; preds = %26, %1
ret void
}

LLVM IR (-O2):
@WNOHANG = global i32 0
@.str = [20 x i8] c"Script: [%d] exited\00"
define void @check_script(i64* nocapture %0) {
%2 = alloca i32
%3 = alloca [30 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%6 = load i64, i64* %0
%7 = icmp eq i64 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %1
%9 = load i32, i32* @WNOHANG
%10 = call i64 @waitpid(i64 %6, i32* %2, i32 %9)
%11 = load i64, i64* %0
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 %10)
%15 = call i32 @do_log(i8* %5)
store i64 0, i64* %0
br label %16
16: ; preds = %8, %13, %1
ret void
}