#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);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stop();
int system(char *);
int test_system() {
  int ret;
  char sys[512];
  ret = system(NULL);
  printf("system 1: ret = %d %s\n", ret, ret != 0 ? "OK" : "");
  stop();
  sprintf(sys, "mkdir -p %s %s", "dir1.fileio.test/subdir.fileio.test",
          "dir2.fileio.test");
  ret = system(sys);
  if (ret == 127)
    printf("system 2: ret = %d /bin/sh unavailable???\n", ret);
  else
    printf("system 2: ret = %d %s\n", ret, ret == 0 ? "OK" : "");
  stop();
  ret = system("wrtzlpfrmpft");
  printf("system 3: ret = %d %s\n", ret, WEXITSTATUS(ret) == 127 ? "OK" : "");
  stop();
}


x86 assembly (clang, -O0):
<test_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1030 <system@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%ecx
lea    0xf14(%rip),%rdx
lea    0xe9c(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <stop@plt>
lea    -0x210(%rbp),%rdi
lea    0xe75(%rip),%rsi
lea    0xe7d(%rip),%rdx
lea    0xe9a(%rip),%rcx
call   1070 <sprintf@plt>
lea    -0x210(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x7f,-0x8(%rbp)
jne    11e7 <test_system+0x97>
mov    -0x8(%rbp),%esi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1210 <test_system+0xc0>
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%ecx
lea    0xe94(%rip),%rdx
lea    0xe1c(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rdx
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <stop@plt>
lea    0xe82(%rip),%rdi
call   1030 <system@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x214(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    -0x214(%rbp),%esi
mov    %eax,%ecx
lea    0xe42(%rip),%rdx
lea    0xdca(%rip),%rax
cmp    $0x7f,%ecx
cmove  %rax,%rdx
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <stop@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_system>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
xor    %edi,%edi
call   1030 <system@plt>
test   %eax,%eax
lea    0xf1b(%rip),%rbx
lea    0xea3(%rip),%r15
mov    %r15,%rdx
cmove  %rbx,%rdx
lea    0xe7e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <stop@plt>
lea    0xe81(%rip),%rsi
lea    0xe89(%rip),%rdx
lea    0xea6(%rip),%rcx
mov    %rsp,%r14
mov    %r14,%rdi
call   1070 <sprintf@plt>
mov    %r14,%rdi
call   1030 <system@plt>
cmp    $0x7f,%eax
jne    11d4 <test_system+0x84>
lea    0xe98(%rip),%rdi
mov    $0x7f,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ed <test_system+0x9d>
test   %eax,%eax
mov    %rbx,%rdx
cmove  %r15,%rdx
lea    0xea5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <stop@plt>
lea    0xea5(%rip),%rdi
call   1030 <system@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x7f,%eax
cmove  %r15,%rbx
lea    0xe96(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <stop@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"system 1: ret = %d %s\0A\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [15 x i8] c"mkdir -p %s %s\00"
@.str.4 = [36 x i8] c"dir1.fileio.test/subdir.fileio.test\00"
@.str.5 = [17 x i8] c"dir2.fileio.test\00"
@.str.6 = [43 x i8] c"system 2: ret = %d /bin/sh unavailable???\0A\00"
@.str.7 = [23 x i8] c"system 2: ret = %d %s\0A\00"
@.str.8 = [13 x i8] c"wrtzlpfrmpft\00"
@.str.9 = [23 x i8] c"system 3: ret = %d %s\0A\00"
define i32 @test_system() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = call i32 @system(i8* null)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
%8 = zext i1 %7 to i64
%9 = select i1 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %9)
%11 = call i32 (...) @stop()
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%13 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%15 = call i32 @system(i8* %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp eq i32 %16, 127
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = load i32, i32* %2
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 %19)
br label %28
21: ; preds = %0
%22 = load i32, i32* %2
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %22, i8* %26)
br label %28
28: ; preds = %21, %18
%29 = call i32 (...) @stop()
%30 = call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = load i32, i32* %2
%33 = call i32 @WEXITSTATUS(i32 %32)
%34 = icmp eq i32 %33, 127
%35 = zext i1 %34 to i64
%36 = select i1 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %31, i8* %36)
%38 = call i32 (...) @stop()
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [23 x i8] c"system 1: ret = %d %s\0A\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [15 x i8] c"mkdir -p %s %s\00"
@.str.4 = [36 x i8] c"dir1.fileio.test/subdir.fileio.test\00"
@.str.5 = [17 x i8] c"dir2.fileio.test\00"
@.str.6 = [43 x i8] c"system 2: ret = %d /bin/sh unavailable???\0A\00"
@.str.7 = [23 x i8] c"system 2: ret = %d %s\0A\00"
@.str.8 = [13 x i8] c"wrtzlpfrmpft\00"
@.str.9 = [23 x i8] c"system 3: ret = %d %s\0A\00"
define i32 @test_system() {
%1 = alloca [512 x i8]
%2 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @system(i8* null)
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %5)
%7 = tail call i32 (...) @stop()
%8 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%9 = call i32 @system(i8* %2)
%10 = icmp eq i32 %9, 127
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i32 127)
br label %17
13: ; preds = %0
%14 = icmp eq i32 %9, 0
%15 = select i1 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %9, i8* %15)
br label %17
17: ; preds = %13, %11
%18 = tail call i32 (...) @stop()
%19 = tail call i32 @system(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%20 = tail call i32 @WEXITSTATUS(i32 %19)
%21 = icmp eq i32 %20, 127
%22 = select i1 %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%23 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i32 %19, i8* %22)
%24 = tail call i32 (...) @stop()
ret i32 undef
}