#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 /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, int);
int system(char *);
int chaz_OS_run_sh_via_cmd_exe(const char *command) {
  size_t i;
  size_t size;
  char *sh_command;
  char *p;
  int retval;
  size = sizeof("sh -c \"\"");
  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;
    }
  }
  sh_command = (char *)malloc(size);
  p = sh_command;
  memcpy(p, "sh -c \"", 7);
  p += 7;
  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++ = '"';
  *p++ = '\0';
  retval = system(sh_command);
  free(sh_command);
  return retval;
}


x86 assembly (clang, -O0):
<chaz_OS_run_sh_via_cmd_exe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x9,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     120b <chaz_OS_run_sh_via_cmd_exe+0xcb>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2d(%rbp)
movsbl -0x2d(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x21,%eax
je     11d8 <chaz_OS_run_sh_via_cmd_exe+0x98>
jmp    1194 <chaz_OS_run_sh_via_cmd_exe+0x54>
mov    -0x34(%rbp),%eax
sub    $0x22,%eax
je     11c7 <chaz_OS_run_sh_via_cmd_exe+0x87>
jmp    11a5 <chaz_OS_run_sh_via_cmd_exe+0x65>
mov    -0x34(%rbp),%eax
sub    $0x25,%eax
je     11d8 <chaz_OS_run_sh_via_cmd_exe+0x98>
jmp    11b6 <chaz_OS_run_sh_via_cmd_exe+0x76>
mov    -0x34(%rbp),%eax
sub    $0x5c,%eax
jne    11e9 <chaz_OS_run_sh_via_cmd_exe+0xa9>
jmp    11c7 <chaz_OS_run_sh_via_cmd_exe+0x87>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    11f5 <chaz_OS_run_sh_via_cmd_exe+0xb5>
mov    -0x18(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x18(%rbp)
jmp    11f5 <chaz_OS_run_sh_via_cmd_exe+0xb5>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11fa <chaz_OS_run_sh_via_cmd_exe+0xba>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115c <chaz_OS_run_sh_via_cmd_exe+0x1c>
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdd5(%rip),%rsi
mov    $0x7,%edx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1346 <chaz_OS_run_sh_via_cmd_exe+0x206>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2e(%rbp)
movsbl -0x2e(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x21,%eax
je     12df <chaz_OS_run_sh_via_cmd_exe+0x19f>
jmp    1281 <chaz_OS_run_sh_via_cmd_exe+0x141>
mov    -0x38(%rbp),%eax
sub    $0x22,%eax
je     12b4 <chaz_OS_run_sh_via_cmd_exe+0x174>
jmp    1292 <chaz_OS_run_sh_via_cmd_exe+0x152>
mov    -0x38(%rbp),%eax
sub    $0x25,%eax
je     12df <chaz_OS_run_sh_via_cmd_exe+0x19f>
jmp    12a3 <chaz_OS_run_sh_via_cmd_exe+0x163>
mov    -0x38(%rbp),%eax
sub    $0x5c,%eax
jne    131c <chaz_OS_run_sh_via_cmd_exe+0x1dc>
jmp    12b4 <chaz_OS_run_sh_via_cmd_exe+0x174>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x5c,(%rax)
mov    -0x2e(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    1330 <chaz_OS_run_sh_via_cmd_exe+0x1f0>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x22,(%rax)
mov    -0x2e(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x22,(%rax)
jmp    1330 <chaz_OS_run_sh_via_cmd_exe+0x1f0>
mov    -0x2e(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    1335 <chaz_OS_run_sh_via_cmd_exe+0x1f5>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1249 <chaz_OS_run_sh_via_cmd_exe+0x109>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x22,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_OS_run_sh_via_cmd_exe>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%cl
test   %cl,%cl
je     11a1 <chaz_OS_run_sh_via_cmd_exe+0x61>
lea    0x1(%rbx),%rax
mov    $0x9,%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     11a6 <chaz_OS_run_sh_via_cmd_exe+0x66>
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>
mov    $0x9,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe4b(%rip),%rsi
mov    %rax,%rdi
mov    $0x7,%edx
call   1050 <memcpy@plt>
mov    %r14,%rax
add    $0x7,%rax
mov    (%rbx),%cl
test   %cl,%cl
je     1236 <chaz_OS_run_sh_via_cmd_exe+0xf6>
add    $0x1,%rbx
jmp    11f9 <chaz_OS_run_sh_via_cmd_exe+0xb9>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x22,(%rax)
mov    %cl,0x1(%rax)
movb   $0x22,0x2(%rax)
add    $0x3,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     1236 <chaz_OS_run_sh_via_cmd_exe+0xf6>
movsbl %cl,%edx
cmp    $0x24,%edx
jg     1220 <chaz_OS_run_sh_via_cmd_exe+0xe0>
cmp    $0x21,%edx
je     11e0 <chaz_OS_run_sh_via_cmd_exe+0xa0>
cmp    $0x22,%edx
je     122a <chaz_OS_run_sh_via_cmd_exe+0xea>
mov    %cl,(%rax)
add    $0x1,%rax
jmp    11ee <chaz_OS_run_sh_via_cmd_exe+0xae>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x25,%edx
je     11e0 <chaz_OS_run_sh_via_cmd_exe+0xa0>
cmp    $0x5c,%edx
jne    120b <chaz_OS_run_sh_via_cmd_exe+0xcb>
movb   $0x5c,(%rax)
mov    %cl,0x1(%rax)
add    $0x2,%rax
jmp    11ee <chaz_OS_run_sh_via_cmd_exe+0xae>
movw   $0x22,(%rax)
mov    %r14,%rdi
call   1040 <system@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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