#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 EIO;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ printf(char *, char const *, int);
int setenv(char *, char *, int);
int system(char const *);
int /*<<< orphan*/ warnx(char *, char const *);
int _keystore_execute_cmd(const char *cmd, const char *msg_cmd) {
  int rc;
  rc = setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin", 1);
  if (rc < 0)
    return rc;
  rc = system(cmd);
  if (WIFEXITED(rc)) {
    rc = WEXITSTATUS(rc);
    if (rc != 0)
      printf("%s exit code: %d\n", msg_cmd, rc);
  } else {
    rc = -EIO;
    warnx("%s terminated abnormally", msg_cmd);
  }
  return rc;
}


x86 assembly (clang, -O0):
<_keystore_execute_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe89(%rip),%rdi
lea    0xe87(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a0 <_keystore_execute_cmd+0x40>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120f <_keystore_execute_cmd+0xaf>
mov    -0x10(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11eb <_keystore_execute_cmd+0x8b>
mov    -0x1c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11e6 <_keystore_execute_cmd+0x86>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
jmp    1209 <_keystore_execute_cmd+0xa9>
xor    %eax,%eax
mov    0x2dec(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe31(%rip),%rdi
call   1060 <warnx@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_keystore_execute_cmd>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe8f(%rip),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
test   %eax,%eax
js     11bc <_keystore_execute_cmd+0x5c>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
je     11c0 <_keystore_execute_cmd+0x60>
mov    %ebx,%edi
call   1070 <WEXITSTATUS@plt>
test   %eax,%eax
je     11dc <_keystore_execute_cmd+0x7c>
mov    %eax,%ebp
lea    0xe73(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
jmp    11de <_keystore_execute_cmd+0x7e>
mov    %eax,%ebp
jmp    11de <_keystore_execute_cmd+0x7e>
mov    0x2e19(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
lea    0xe63(%rip),%rdi
mov    %r14,%rsi
call   1060 <warnx@plt>
jmp    11de <_keystore_execute_cmd+0x7e>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [30 x i8] c"/bin:/sbin:/usr/bin:/usr/sbin\00"
@.str.2 = [18 x i8] c"%s exit code: %d\0A\00"
@EIO = global i32 0
@.str.3 = [25 x i8] c"%s terminated abnormally\00"
define i32 @_keystore_execute_cmd(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32, i32* %6
store i32 %11, i32* %3
br label %35
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @system(i8* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i64 @WIFEXITED(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %12
%19 = load i32, i32* %6
%20 = call i32 @WEXITSTATUS(i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i8*, i8** %5
%25 = load i32, i32* %6
%26 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %24, i32 %25)
br label %27
27: ; preds = %23, %18
br label %33
28: ; preds = %12
%29 = load i32, i32* @EIO
%30 = sub nsw i32 0, %29
store i32 %30, i32* %6
%31 = load i8*, i8** %5
%32 = call i32 @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %28, %27
%34 = load i32, i32* %6
store i32 %34, i32* %3
br label %35
35: ; preds = %33, %10
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [30 x i8] c"/bin:/sbin:/usr/bin:/usr/sbin\00"
@.str.2 = [18 x i8] c"%s exit code: %d\0A\00"
@EIO = global i32 0
@.str.3 = [25 x i8] c"%s terminated abnormally\00"
define i32 @_keystore_execute_cmd(i8* nocapture %0, i8* %1) {
%3 = tail call i32 @setenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = tail call i32 @system(i8* %0)
%7 = tail call i64 @WIFEXITED(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %5
%10 = tail call i32 @WEXITSTATUS(i32 %6)
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %10)
br label %18
14: ; preds = %5
%15 = load i32, i32* @EIO
%16 = sub nsw i32 0, %15
%17 = tail call i32 @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %18
18: ; preds = %14, %12, %9, %2
%19 = phi i32 [ %3, %2 ], [ %10, %12 ], [ 0, %9 ], [ %16, %14 ]
ret i32 %19
}