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

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ putenv(char *);
int system(char const *);
int runsyscmd(const char *cmd) {
  int err = 1;
  if (cmd != NULL && *cmd) {
    putenv("PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/sbin/scripts:/usr/sbin/"
           "rc_app");
    err = system(cmd);
    if (WIFEXITED(err))
      err = WEXITSTATUS(err);
  }
  return err;
}


x86 assembly (clang, -O0):
<runsyscmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a8 <runsyscmd+0x68>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a8 <runsyscmd+0x68>
lea    0xe8b(%rip),%rdi
call   1040 <putenv@plt>
mov    -0x8(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11a3 <runsyscmd+0x63>
mov    -0xc(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    %eax,-0xc(%rbp)
jmp    11a8 <runsyscmd+0x68>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runsyscmd>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%ebp
test   %rdi,%rdi
je     1184 <runsyscmd+0x44>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1184 <runsyscmd+0x44>
lea    0xea4(%rip),%rdi
call   1040 <putenv@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     1184 <runsyscmd+0x44>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <WEXITSTATUS@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [70 x i8] c"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/sbin/scripts:/usr/sbin/rc_app\00"
define i32 @runsyscmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 1, i32* %3
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %22
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %6
%12 = call i32 @putenv(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %2
%14 = call i32 @system(i8* %13)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = call i64 @WIFEXITED(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* %3
%20 = call i32 @WEXITSTATUS(i32 %19)
store i32 %20, i32* %3
br label %21
21: ; preds = %18, %11
br label %22
22: ; preds = %21, %6, %1
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [70 x i8] c"PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/sbin/scripts:/usr/sbin/rc_app\00"
define i32 @runsyscmd(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i32 @putenv(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @system(i8* %0)
%9 = tail call i64 @WIFEXITED(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 @WEXITSTATUS(i32 %8)
br label %13
13: ; preds = %6, %11, %3, %1
%14 = phi i32 [ %12, %11 ], [ %8, %6 ], [ 1, %3 ], [ 1, %1 ]
ret i32 %14
}