#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 */
char *chaz_Util_join(char *, char *, char *, char *, char const *, char *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int system(char *);
int chaz_OS_run_sh_via_cmd_exe(const char *command, const char *path) {
  size_t i;
  size_t size;
  char *escaped_command;
  char *wrapped_command;
  char *p;
  int retval;
  size = 0;
  for (i = 0; command[i] != '\0'; i++) {
    char c = command[i];
    switch (c) {
    case '"':
    case '\\':
      size += 2;
      break;
    case '%':
    case '!':
      size += 3;
      break;
    default:
      size += 1;
      break;
    }
  }
  escaped_command = (char *)malloc(size + 1);
  p = escaped_command;
  for (i = 0; command[i] != '\0'; i++) {
    char c = command[i];
    switch (c) {
    case '"':
    case '\\':
      *p++ = '\\';
      *p++ = c;
      break;
    case '%':
    case '!':
      *p++ = '"';
      *p++ = c;
      *p++ = '"';
      break;
    default:
      *p++ = c;
      break;
    }
  }
  *p++ = '\0';
  wrapped_command = chaz_Util_join("", "sh -c \"", escaped_command, "\" > ",
                                   path, " 2>&1", NULL);
  retval = system(wrapped_command);
  free(wrapped_command);
  free(escaped_command);
  return retval;
}


x86 assembly (clang, -O0):
<chaz_OS_run_sh_via_cmd_exe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     120f <chaz_OS_run_sh_via_cmd_exe+0xcf>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x3d(%rbp)
movsbl -0x3d(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0x21,%eax
je     11dc <chaz_OS_run_sh_via_cmd_exe+0x9c>
jmp    1198 <chaz_OS_run_sh_via_cmd_exe+0x58>
mov    -0x44(%rbp),%eax
sub    $0x22,%eax
je     11cb <chaz_OS_run_sh_via_cmd_exe+0x8b>
jmp    11a9 <chaz_OS_run_sh_via_cmd_exe+0x69>
mov    -0x44(%rbp),%eax
sub    $0x25,%eax
je     11dc <chaz_OS_run_sh_via_cmd_exe+0x9c>
jmp    11ba <chaz_OS_run_sh_via_cmd_exe+0x7a>
mov    -0x44(%rbp),%eax
sub    $0x5c,%eax
jne    11ed <chaz_OS_run_sh_via_cmd_exe+0xad>
jmp    11cb <chaz_OS_run_sh_via_cmd_exe+0x8b>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    11f9 <chaz_OS_run_sh_via_cmd_exe+0xb9>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    11f9 <chaz_OS_run_sh_via_cmd_exe+0xb9>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11fe <chaz_OS_run_sh_via_cmd_exe+0xbe>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1160 <chaz_OS_run_sh_via_cmd_exe+0x20>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     132d <chaz_OS_run_sh_via_cmd_exe+0x1ed>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x3e(%rbp)
movsbl -0x3e(%rbp),%eax
mov    %eax,-0x48(%rbp)
sub    $0x21,%eax
je     12c6 <chaz_OS_run_sh_via_cmd_exe+0x186>
jmp    1268 <chaz_OS_run_sh_via_cmd_exe+0x128>
mov    -0x48(%rbp),%eax
sub    $0x22,%eax
je     129b <chaz_OS_run_sh_via_cmd_exe+0x15b>
jmp    1279 <chaz_OS_run_sh_via_cmd_exe+0x139>
mov    -0x48(%rbp),%eax
sub    $0x25,%eax
je     12c6 <chaz_OS_run_sh_via_cmd_exe+0x186>
jmp    128a <chaz_OS_run_sh_via_cmd_exe+0x14a>
mov    -0x48(%rbp),%eax
sub    $0x5c,%eax
jne    1303 <chaz_OS_run_sh_via_cmd_exe+0x1c3>
jmp    129b <chaz_OS_run_sh_via_cmd_exe+0x15b>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x5c,(%rax)
mov    -0x3e(%rbp),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
jmp    1317 <chaz_OS_run_sh_via_cmd_exe+0x1d7>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x22,(%rax)
mov    -0x3e(%rbp),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x22,(%rax)
jmp    1317 <chaz_OS_run_sh_via_cmd_exe+0x1d7>
mov    -0x3e(%rbp),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
jmp    131c <chaz_OS_run_sh_via_cmd_exe+0x1dc>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1230 <chaz_OS_run_sh_via_cmd_exe+0xf0>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%r8
lea    0xcbe(%rip),%rdi
lea    0xcab(%rip),%rsi
lea    0xcac(%rip),%rcx
lea    0xcaa(%rip),%r9
xor    %eax,%eax
movq   $0x0,(%rsp)
call   1050 <chaz_Util_join@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x3c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_OS_run_sh_via_cmd_exe>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%cl
test   %cl,%cl
je     11a7 <chaz_OS_run_sh_via_cmd_exe+0x67>
lea    0x1(%rbx),%rax
xor    %edi,%edi
jmp    1173 <chaz_OS_run_sh_via_cmd_exe+0x33>
nopl   0x0(%rax,%rax,1)
mov    $0x3,%ecx
add    %rcx,%rdi
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
je     11a1 <chaz_OS_run_sh_via_cmd_exe+0x61>
movsbl %cl,%edx
mov    $0x2,%ecx
cmp    $0x24,%edx
jg     1190 <chaz_OS_run_sh_via_cmd_exe+0x50>
cmp    $0x21,%edx
je     1160 <chaz_OS_run_sh_via_cmd_exe+0x20>
cmp    $0x22,%edx
je     1165 <chaz_OS_run_sh_via_cmd_exe+0x25>
jmp    119a <chaz_OS_run_sh_via_cmd_exe+0x5a>
nopl   0x0(%rax)
cmp    $0x5c,%edx
je     1165 <chaz_OS_run_sh_via_cmd_exe+0x25>
cmp    $0x25,%edx
je     1160 <chaz_OS_run_sh_via_cmd_exe+0x20>
mov    $0x1,%ecx
jmp    1165 <chaz_OS_run_sh_via_cmd_exe+0x25>
add    $0x1,%rdi
jmp    11ac <chaz_OS_run_sh_via_cmd_exe+0x6c>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    (%rbx),%cl
test   %cl,%cl
je     1226 <chaz_OS_run_sh_via_cmd_exe+0xe6>
add    $0x1,%rbx
mov    %r15,%rax
jmp    11e9 <chaz_OS_run_sh_via_cmd_exe+0xa9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x22,(%rax)
mov    %cl,0x1(%rax)
movb   $0x22,0x2(%rax)
add    $0x3,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     1229 <chaz_OS_run_sh_via_cmd_exe+0xe9>
movsbl %cl,%edx
cmp    $0x24,%edx
jg     1210 <chaz_OS_run_sh_via_cmd_exe+0xd0>
cmp    $0x21,%edx
je     11d0 <chaz_OS_run_sh_via_cmd_exe+0x90>
cmp    $0x22,%edx
je     121a <chaz_OS_run_sh_via_cmd_exe+0xda>
mov    %cl,(%rax)
add    $0x1,%rax
jmp    11de <chaz_OS_run_sh_via_cmd_exe+0x9e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x25,%edx
je     11d0 <chaz_OS_run_sh_via_cmd_exe+0x90>
cmp    $0x5c,%edx
jne    11fb <chaz_OS_run_sh_via_cmd_exe+0xbb>
movb   $0x5c,(%rax)
mov    %cl,0x1(%rax)
add    $0x2,%rax
jmp    11de <chaz_OS_run_sh_via_cmd_exe+0x9e>
mov    %r15,%rax
movb   $0x0,(%rax)
movq   $0x0,(%rsp)
lea    0xdd1(%rip),%rdi
lea    0xdbe(%rip),%rsi
lea    0xdbf(%rip),%rcx
lea    0xdbd(%rip),%r9
mov    %r15,%rdx
mov    %r14,%r8
call   1050 <chaz_Util_join@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <system@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [8 x i8] c"sh -c \22\00"
@.str.2 = [5 x i8] c"\22 > \00"
@.str.3 = [6 x i8] c" 2>&1\00"
define i32 @chaz_OS_run_sh_via_cmd_exe(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %6
store i64 0, i64* %5
br label %13
13: ; preds = %37, %2
%14 = load i8*, i8** %3
%15 = load i64, i64* %5
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %40
20: ; preds = %13
%21 = load i8*, i8** %3
%22 = load i64, i64* %5
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8, i8* %23
store i8 %24, i8* %11
%25 = load i8, i8* %11
%26 = sext i8 %25 to i32
switch i32 %26, label %33 [
i32 34, label %27
i32 92, label %27
i32 37, label %30
i32 33, label %30
]
27: ; preds = %20, %20
%28 = load i64, i64* %6
%29 = add i64 %28, 2
store i64 %29, i64* %6
br label %36
30: ; preds = %20, %20
%31 = load i64, i64* %6
%32 = add i64 %31, 3
store i64 %32, i64* %6
br label %36
33: ; preds = %20
%34 = load i64, i64* %6
%35 = add i64 %34, 1
store i64 %35, i64* %6
br label %36
36: ; preds = %33, %30, %27
br label %37
37: ; preds = %36
%38 = load i64, i64* %5
%39 = add i64 %38, 1
store i64 %39, i64* %5
br label %13
40: ; preds = %13
%41 = load i64, i64* %6
%42 = add i64 %41, 1
%43 = call i64 @malloc(i64 %42)
%44 = inttoptr i64 %43 to i8*
store i8* %44, i8** %7
%45 = load i8*, i8** %7
store i8* %45, i8** %9
store i64 0, i64* %5
br label %46
46: ; preds = %79, %40
%47 = load i8*, i8** %3
%48 = load i64, i64* %5
%49 = getelementptr inbounds i8, i8* %47, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %82
53: ; preds = %46
%54 = load i8*, i8** %3
%55 = load i64, i64* %5
%56 = getelementptr inbounds i8, i8* %54, i64 %55
%57 = load i8, i8* %56
store i8 %57, i8* %12
%58 = load i8, i8* %12
%59 = sext i8 %58 to i32
switch i32 %59, label %74 [
i32 34, label %60
i32 92, label %60
i32 37, label %66
i32 33, label %66
]
60: ; preds = %53, %53
%61 = load i8*, i8** %9
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %9
store i8 92, i8* %61
%63 = load i8, i8* %12
%64 = load i8*, i8** %9
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %9
store i8 %63, i8* %64
br label %78
66: ; preds = %53, %53
%67 = load i8*, i8** %9
%68 = getelementptr inbounds i8, i8* %67, i32 1
store i8* %68, i8** %9
store i8 34, i8* %67
%69 = load i8, i8* %12
%70 = load i8*, i8** %9
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %9
store i8 %69, i8* %70
%72 = load i8*, i8** %9
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %9
store i8 34, i8* %72
br label %78
74: ; preds = %53
%75 = load i8, i8* %12
%76 = load i8*, i8** %9
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %9
store i8 %75, i8* %76
br label %78
78: ; preds = %74, %66, %60
br label %79
79: ; preds = %78
%80 = load i64, i64* %5
%81 = add i64 %80, 1
store i64 %81, i64* %5
br label %46
82: ; preds = %46
%83 = load i8*, i8** %9
%84 = getelementptr inbounds i8, i8* %83, i32 1
store i8* %84, i8** %9
store i8 0, i8* %83
%85 = load i8*, i8** %7
%86 = load i8*, i8** %4
%87 = call i8* @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %85, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %86, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* null)
store i8* %87, i8** %8
%88 = load i8*, i8** %8
%89 = call i32 @system(i8* %88)
store i32 %89, i32* %10
%90 = load i8*, i8** %8
%91 = call i32 @free(i8* %90)
%92 = load i8*, i8** %7
%93 = call i32 @free(i8* %92)
%94 = load i32, i32* %10
ret i32 %94
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [8 x i8] c"sh -c \22\00"
@.str.2 = [5 x i8] c"\22 > \00"
@.str.3 = [6 x i8] c" 2>&1\00"
define i32 @chaz_OS_run_sh_via_cmd_exe(i8* nocapture %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %21, label %5
5: ; preds = %2, %12
%6 = phi i8 [ %17, %12 ], [ %3, %2 ]
%7 = phi i64 [ %15, %12 ], [ 0, %2 ]
%8 = phi i64 [ %14, %12 ], [ 0, %2 ]
%9 = sext i8 %6 to i32
switch i32 %9, label %11 [
i32 34, label %12
i32 92, label %12
i32 37, label %10
i32 33, label %10
]
10: ; preds = %5, %5
br label %12
11: ; preds = %5
br label %12
12: ; preds = %5, %5, %11, %10
%13 = phi i64 [ 1, %11 ], [ 3, %10 ], [ 2, %5 ], [ 2, %5 ]
%14 = add i64 %8, %13
%15 = add i64 %7, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %5
19: ; preds = %12
%20 = add i64 %14, 1
br label %21
21: ; preds = %19, %2
%22 = phi i64 [ 1, %2 ], [ %20, %19 ]
%23 = tail call i64 @malloc(i64 %22)
%24 = inttoptr i64 %23 to i8*
%25 = load i8, i8* %0
%26 = icmp eq i8 %25, 0
br i1 %26, label %47, label %27
27: ; preds = %21, %41
%28 = phi i8 [ %45, %41 ], [ %25, %21 ]
%29 = phi i64 [ %43, %41 ], [ 0, %21 ]
%30 = phi i8* [ %42, %41 ], [ %24, %21 ]
%31 = sext i8 %28 to i32
switch i32 %31, label %39 [
i32 34, label %32
i32 92, label %32
i32 37, label %35
i32 33, label %35
]
32: ; preds = %27, %27
%33 = getelementptr inbounds i8, i8* %30, i64 1
store i8 92, i8* %30
%34 = getelementptr inbounds i8, i8* %30, i64 2
store i8 %28, i8* %33
br label %41
35: ; preds = %27, %27
%36 = getelementptr inbounds i8, i8* %30, i64 1
store i8 34, i8* %30
%37 = getelementptr inbounds i8, i8* %30, i64 2
store i8 %28, i8* %36
%38 = getelementptr inbounds i8, i8* %30, i64 3
store i8 34, i8* %37
br label %41
39: ; preds = %27
%40 = getelementptr inbounds i8, i8* %30, i64 1
store i8 %28, i8* %30
br label %41
41: ; preds = %39, %35, %32
%42 = phi i8* [ %40, %39 ], [ %38, %35 ], [ %34, %32 ]
%43 = add i64 %29, 1
%44 = getelementptr inbounds i8, i8* %0, i64 %43
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 0
br i1 %46, label %47, label %27
47: ; preds = %41, %21
%48 = phi i8* [ %24, %21 ], [ %42, %41 ]
store i8 0, i8* %48
%49 = tail call i8* @chaz_Util_join(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* null)
%50 = tail call i32 @system(i8* %49)
%51 = tail call i32 @free(i8* %49)
%52 = tail call i32 @free(i8* %24)
ret i32 %50
}