#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*/ LOG_ERR;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int WTERMSIG(int);
int /*<<< orphan*/ do_log(int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ run_netplug_bg(char *, char *);
int waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int run_netplug(char *ifname, char *action) {
  pid_t pid = run_netplug_bg(ifname, action);
  int status, ret;
  if ((ret = waitpid(pid, &status, 0)) == -1) {
    do_log(LOG_ERR, "waitpid: %m");
    exit(1);
  }
  return WIFEXITED(status) ? WEXITSTATUS(status) : -WTERMSIG(status);
}


x86 assembly (clang, -O0):
<run_netplug>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <run_netplug_bg@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11c9 <run_netplug+0x59>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1040 <do_log@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11eb <run_netplug+0x7b>
mov    -0x18(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,-0x20(%rbp)
jmp    11fc <run_netplug+0x8c>
mov    -0x18(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_netplug>:
push   %rax
call   1030 <run_netplug_bg@plt>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1070 <waitpid@plt>
cmp    $0xffffffff,%eax
je     11ab <run_netplug+0x3b>
mov    0x4(%rsp),%edi
call   1080 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     11a2 <run_netplug+0x32>
call   1060 <WEXITSTATUS@plt>
pop    %rcx
ret
call   1050 <WTERMSIG@plt>
neg    %eax
pop    %rcx
ret
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1040 <do_log@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [12 x i8] c"waitpid: %m\00"
define i32 @run_netplug(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = call i32 @run_netplug_bg(i8* %8, i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = call i32 @waitpid(i32 %11, i32* %6, i32 0)
store i32 %12, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @LOG_ERR
%16 = call i32 @do_log(i32 %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* %6
%20 = call i64 @WIFEXITED(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %6
%24 = call i32 @WEXITSTATUS(i32 %23)
br label %29
25: ; preds = %18
%26 = load i32, i32* %6
%27 = call i32 @WTERMSIG(i32 %26)
%28 = sub nsw i32 0, %27
br label %29
29: ; preds = %25, %22
%30 = phi i32 [ %24, %22 ], [ %28, %25 ]
ret i32 %30
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [12 x i8] c"waitpid: %m\00"
define i32 @run_netplug(i8* %0, i8* %1) {
%3 = alloca i32
%4 = tail call i32 @run_netplug_bg(i8* %0, i8* %1)
%5 = bitcast i32* %3 to i8*
%6 = call i32 @waitpid(i32 %4, i32* %3, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @LOG_ERR
%10 = call i32 @do_log(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i32, i32* %3
%14 = call i64 @WIFEXITED(i32 %13)
%15 = icmp eq i64 %14, 0
%16 = load i32, i32* %3
br i1 %15, label %19, label %17
17: ; preds = %12
%18 = call i32 @WEXITSTATUS(i32 %16)
br label %22
19: ; preds = %12
%20 = call i32 @WTERMSIG(i32 %16)
%21 = sub nsw i32 0, %20
br label %22
22: ; preds = %19, %17
%23 = phi i32 [ %18, %17 ], [ %21, %19 ]
ret i32 %23
}