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

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ printf(char *, ...);
int cc_up_is_valid_system_return(pid_t status) {
  if (status == -1) {
    printf("system error, status:%d \n", status);
    return -1;
  } else {
    printf("status value is : 0x%x \n", status);
    if (WIFEXITED(status)) {
      if (0 == WEXITSTATUS(status)) {
        printf("shell exe successfully.\n");
        return 0;
      } else {
        printf("run shell script fail, script exit code: %d\n",
               WEXITSTATUS(status));
        return -1;
      }
    } else {
      printf("exit status = %d  \n", WEXITSTATUS(status));
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<cc_up_is_valid_system_return>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1162 <cc_up_is_valid_system_return+0x32>
mov    -0x8(%rbp),%esi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <cc_up_is_valid_system_return+0xc6>
mov    -0x8(%rbp),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11d7 <cc_up_is_valid_system_return+0xa7>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11b3 <cc_up_is_valid_system_return+0x83>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <cc_up_is_valid_system_return+0xc6>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <cc_up_is_valid_system_return+0xc6>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cc_up_is_valid_system_return>:
push   %r14
push   %rbx
push   %rax
cmp    $0xffffffff,%edi
je     1185 <cc_up_is_valid_system_return+0x45>
mov    %edi,%ebx
lea    0xec8(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <WIFEXITED@plt>
mov    %rax,%r14
mov    %ebx,%edi
call   1050 <WEXITSTATUS@plt>
test   %r14,%r14
je     119f <cc_up_is_valid_system_return+0x5f>
test   %eax,%eax
je     11b6 <cc_up_is_valid_system_return+0x76>
mov    %ebx,%edi
call   1050 <WEXITSTATUS@plt>
lea    0xeb0(%rip),%rdi
jmp    11a6 <cc_up_is_valid_system_return+0x66>
lea    0xe74(%rip),%rdi
mov    $0xffffffff,%ebx
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c4 <cc_up_is_valid_system_return+0x84>
lea    0xeba(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
jmp    11c4 <cc_up_is_valid_system_return+0x84>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"system error, status:%d \0A\00"
@.str.1 = [25 x i8] c"status value is : 0x%x \0A\00"
@.str.2 = [25 x i8] c"shell exe successfully.\0A\00"
@.str.3 = [45 x i8] c"run shell script fail, script exit code: %d\0A\00"
@.str.4 = [20 x i8] c"exit status = %d \0A\00"
define i32 @cc_up_is_valid_system_return(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 -1, i32* %2
br label %29
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %3
%13 = call i64 @WIFEXITED(i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %9
%16 = load i32, i32* %3
%17 = call i32 @WEXITSTATUS(i32 %16)
%18 = icmp eq i32 0, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %29
21: ; preds = %15
%22 = load i32, i32* %3
%23 = call i32 @WEXITSTATUS(i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %23)
store i32 -1, i32* %2
br label %29
25: ; preds = %9
%26 = load i32, i32* %3
%27 = call i32 @WEXITSTATUS(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %27)
store i32 -1, i32* %2
br label %29
29: ; preds = %25, %21, %19, %6
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@.str = [26 x i8] c"system error, status:%d \0A\00"
@.str.1 = [25 x i8] c"status value is : 0x%x \0A\00"
@.str.3 = [45 x i8] c"run shell script fail, script exit code: %d\0A\00"
@.str.4 = [20 x i8] c"exit status = %d \0A\00"
@str = [24 x i8] c"shell exe successfully.\00"
define i32 @cc_up_is_valid_system_return(i32 %0) {
%2 = icmp eq i32 %0, -1
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 -1)
br label %19
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%7 = tail call i64 @WIFEXITED(i32 %0)
%8 = icmp eq i64 %7, 0
%9 = tail call i32 @WEXITSTATUS(i32 %0)
br i1 %8, label %17, label %10
10: ; preds = %5
%11 = icmp eq i32 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %19
14: ; preds = %10
%15 = tail call i32 @WEXITSTATUS(i32 %0)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %19
17: ; preds = %5
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %9)
br label %19
19: ; preds = %17, %14, %12, %3
%20 = phi i32 [ -1, %3 ], [ 0, %12 ], [ -1, %14 ], [ -1, %17 ]
ret i32 %20
}