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


x86 assembly (clang, -O0):
<test_system>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
lea    -0x210(%rbp),%rdi
lea    0xea7(%rip),%rsi
lea    0xeaf(%rip),%rdx
lea    0xecc(%rip),%rcx
call   1060 <sprintf@plt>
lea    -0x210(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x7f,-0x8(%rbp)
jne    119b <test_system+0x5b>
mov    -0x8(%rbp),%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c4 <test_system+0x84>
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%ecx
lea    0xec6(%rip),%rdx
lea    0xed7(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rdx
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xebe(%rip),%rdi
call   1030 <system@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x214(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
mov    -0x214(%rbp),%esi
mov    %eax,%ecx
lea    0xe7b(%rip),%rdx
lea    0xe8c(%rip),%rax
cmp    $0x7f,%ecx
cmove  %rax,%rdx
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_system>:
push   %rbx
sub    $0x200,%rsp
lea    0xeb1(%rip),%rsi
lea    0xeb9(%rip),%rdx
lea    0xed6(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
cmp    $0x7f,%eax
jne    118a <test_system+0x4a>
lea    0xec8(%rip),%rdi
mov    $0x7f,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ae <test_system+0x6e>
test   %eax,%eax
lea    0xef3(%rip),%rcx
lea    0xed4(%rip),%rdx
cmove  %rcx,%rdx
lea    0xeca(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed4(%rip),%rdi
call   1030 <system@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x7f,%eax
lea    0xeb9(%rip),%rax
lea    0xe9a(%rip),%rdx
cmove  %rax,%rdx
lea    0xeb7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
jmp    1040 <printf@plt>

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

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