#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*/ execvp(char *, char **);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
void exec_complex_command(const char *shell, const char *command) {
  char *av[5];
  int ac = 0;
  char *command2 = (char *)malloc(strlen(command) + 10);
  const char *s;
  int got_eq = 0;
  const char *after_vars;
  while (*command == ' ' || *command == '\t')
    command++;
  after_vars = command;
  for (s = command; *s; s++) {
    if (*s == '=')
      got_eq = 1;
    else if (*s == ' ') {
      if (got_eq) {
        while (*s == ' ' || *s == '\t')
          s++;
        after_vars = s;
        got_eq = 0;
      } else
        break;
    }
  }
  *command2 = 0;
  strncat(command2, command, after_vars - command);
  strcat(command2, "exec ");
  strcat(command2, after_vars);
  av[ac++] = (char *)shell;
  av[ac++] = "-c";
  av[ac++] = command2;
  av[ac] = 0;
  execvp(av[0], av);
}


x86 assembly (clang, -O0):
<exec_complex_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0xa,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x69(%rbp)
je     11ac <exec_complex_command+0x5c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    11bc <exec_complex_command+0x6c>
jmp    11cd <exec_complex_command+0x7d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1187 <exec_complex_command+0x37>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmpb   $0x0,(%rax)
je     12a4 <exec_complex_command+0x154>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3d,%eax
jne    1206 <exec_complex_command+0xb6>
movl   $0x1,-0x5c(%rbp)
jmp    128e <exec_complex_command+0x13e>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1289 <exec_complex_command+0x139>
cmpl   $0x0,-0x5c(%rbp)
je     127f <exec_complex_command+0x12f>
jmp    1225 <exec_complex_command+0xd5>
mov    -0x58(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x6a(%rbp)
je     124a <exec_complex_command+0xfa>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x6a(%rbp)
mov    -0x6a(%rbp),%al
test   $0x1,%al
jne    125a <exec_complex_command+0x10a>
jmp    126b <exec_complex_command+0x11b>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1225 <exec_complex_command+0xd5>
mov    -0x58(%rbp),%rax
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x5c(%rbp)
jmp    1284 <exec_complex_command+0x134>
jmp    12a4 <exec_complex_command+0x154>
jmp    1289 <exec_complex_command+0x139>
jmp    128e <exec_complex_command+0x13e>
jmp    1293 <exec_complex_command+0x143>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    11dd <exec_complex_command+0x8d>
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x68(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1040 <strncat@plt>
mov    -0x50(%rbp),%rdi
lea    0xd30(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x50(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rcx
mov    -0x44(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x44(%rbp)
cltq
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x44(%rbp)
cltq
lea    0xcfa(%rip),%rcx
mov    %rcx,-0x40(%rbp,%rax,8)
mov    -0x50(%rbp),%rcx
mov    -0x44(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x44(%rbp)
cltq
mov    %rcx,-0x40(%rbp,%rax,8)
movslq -0x44(%rbp),%rax
movq   $0x0,-0x40(%rbp,%rax,8)
mov    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1060 <execvp@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_complex_command>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0xa(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rsi
jmp    1187 <exec_complex_command+0x37>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rsi
add    $0x1,%ebx
movzbl (%rsi),%ecx
cmp    $0x9,%cl
je     1180 <exec_complex_command+0x30>
cmp    $0x20,%cl
je     1180 <exec_complex_command+0x30>
xor    %edx,%edx
mov    %rsi,%rax
mov    %rsi,%r12
jmp    11a9 <exec_complex_command+0x59>
xchg   %ax,%ax
mov    0x1(%rax),%cl
add    $0x1,%rax
mov    %edi,%edx
cmp    $0x20,%cl
je     11c0 <exec_complex_command+0x70>
mov    $0x1,%edi
cmp    $0x3d,%cl
je     11a0 <exec_complex_command+0x50>
test   %cl,%cl
je     11e9 <exec_complex_command+0x99>
mov    %edx,%edi
jmp    11a0 <exec_complex_command+0x50>
test   %edx,%edx
je     11e9 <exec_complex_command+0x99>
mov    $0x20,%cl
jmp    11d8 <exec_complex_command+0x88>
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rax),%ecx
add    $0x1,%rax
cmp    $0x20,%cl
je     11d0 <exec_complex_command+0x80>
cmp    $0x9,%cl
je     11d0 <exec_complex_command+0x80>
xor    %edi,%edi
mov    %rax,%r12
jmp    11a0 <exec_complex_command+0x50>
movb   $0x0,(%r15)
mov    %r12d,%edx
sub    %ebx,%edx
mov    %r15,%rdi
call   1040 <strncat@plt>
lea    0xdff(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    %r14,(%rsp)
lea    0xde7(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %r15,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1060 <execvp@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"exec \00"
@.str.1 = [3 x i8] c"-c\00"
define void @exec_complex_command(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [5 x i8*]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
%13 = add nsw i64 %12, 10
%14 = call i64 @malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %7
store i32 0, i32* %9
br label %16
16: ; preds = %28, %2
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 32
br i1 %20, label %26, label %21
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 9
br label %26
26: ; preds = %21, %16
%27 = phi i1 [ true, %16 ], [ %25, %21 ]
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
br label %16
31: ; preds = %26
%32 = load i8*, i8** %4
store i8* %32, i8** %10
%33 = load i8*, i8** %4
store i8* %33, i8** %8
br label %34
34: ; preds = %74, %31
%35 = load i8*, i8** %8
%36 = load i8, i8* %35
%37 = icmp ne i8 %36, 0
br i1 %37, label %38, label %77
38: ; preds = %34
%39 = load i8*, i8** %8
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 61
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 1, i32* %9
br label %73
44: ; preds = %38
%45 = load i8*, i8** %8
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 32
br i1 %48, label %49, label %72
49: ; preds = %44
%50 = load i32, i32* %9
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %70
52: ; preds = %49
br label %53
53: ; preds = %65, %52
%54 = load i8*, i8** %8
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 32
br i1 %57, label %63, label %58
58: ; preds = %53
%59 = load i8*, i8** %8
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 9
br label %63
63: ; preds = %58, %53
%64 = phi i1 [ true, %53 ], [ %62, %58 ]
br i1 %64, label %65, label %68
65: ; preds = %63
%66 = load i8*, i8** %8
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %8
br label %53
68: ; preds = %63
%69 = load i8*, i8** %8
store i8* %69, i8** %10
store i32 0, i32* %9
br label %71
70: ; preds = %49
br label %77
71: ; preds = %68
br label %72
72: ; preds = %71, %44
br label %73
73: ; preds = %72, %43
br label %74
74: ; preds = %73
%75 = load i8*, i8** %8
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %8
br label %34
77: ; preds = %70, %34
%78 = load i8*, i8** %7
store i8 0, i8* %78
%79 = load i8*, i8** %7
%80 = load i8*, i8** %4
%81 = load i8*, i8** %10
%82 = load i8*, i8** %4
%83 = ptrtoint i8* %81 to i64
%84 = ptrtoint i8* %82 to i64
%85 = sub i64 %83, %84
%86 = trunc i64 %85 to i32
%87 = call i32 @strncat(i8* %79, i8* %80, i32 %86)
%88 = load i8*, i8** %7
%89 = call i32 @strcat(i8* %88, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%90 = load i8*, i8** %7
%91 = load i8*, i8** %10
%92 = call i32 @strcat(i8* %90, i8* %91)
%93 = load i8*, i8** %3
%94 = load i32, i32* %6
%95 = add nsw i32 %94, 1
store i32 %95, i32* %6
%96 = sext i32 %94 to i64
%97 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 %96
store i8* %93, i8** %97
%98 = load i32, i32* %6
%99 = add nsw i32 %98, 1
store i32 %99, i32* %6
%100 = sext i32 %98 to i64
%101 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 %100
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %101
%102 = load i8*, i8** %7
%103 = load i32, i32* %6
%104 = add nsw i32 %103, 1
store i32 %104, i32* %6
%105 = sext i32 %103 to i64
%106 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 %105
store i8* %102, i8** %106
%107 = load i32, i32* %6
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 %108
store i8* null, i8** %109
%110 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 0
%111 = load i8*, i8** %110
%112 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 0
%113 = call i32 @execvp(i8* %111, i8** %112)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"exec \00"
@.str.1 = [3 x i8] c"-c\00"
define void @exec_complex_command(i8* %0, i8* %1) {
%3 = alloca [5 x i8*]
%4 = bitcast [5 x i8*]* %3 to i8*
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add nsw i64 %5, 10
%7 = tail call i64 @malloc(i64 %6)
br label %8
8: ; preds = %13, %2
%9 = phi i8* [ %1, %2 ], [ %14, %13 ]
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 32, label %13
i8 9, label %13
]
11: ; preds = %8
%12 = inttoptr i64 %7 to i8*
br label %15
13: ; preds = %8, %8
%14 = getelementptr inbounds i8, i8* %9, i64 1
br label %8
15: ; preds = %11, %29
%16 = phi i8 [ %34, %29 ], [ %10, %11 ]
%17 = phi i8* [ %33, %29 ], [ %9, %11 ]
%18 = phi i32 [ %31, %29 ], [ 0, %11 ]
%19 = phi i8* [ %32, %29 ], [ %9, %11 ]
switch i8 %16, label %28 [
i8 0, label %35
i8 61, label %29
i8 32, label %20
]
20: ; preds = %15
%21 = icmp eq i32 %18, 0
br i1 %21, label %35, label %22
22: ; preds = %20, %25
%23 = phi i8 [ %27, %25 ], [ 32, %20 ]
%24 = phi i8* [ %26, %25 ], [ %17, %20 ]
switch i8 %23, label %29 [
i8 32, label %25
i8 9, label %25
]
25: ; preds = %22, %22
%26 = getelementptr inbounds i8, i8* %24, i64 1
%27 = load i8, i8* %26
br label %22
28: ; preds = %15
br label %29
29: ; preds = %22, %15, %28
%30 = phi i8* [ %17, %15 ], [ %17, %28 ], [ %24, %22 ]
%31 = phi i32 [ 1, %15 ], [ %18, %28 ], [ 0, %22 ]
%32 = phi i8* [ %19, %15 ], [ %19, %28 ], [ %24, %22 ]
%33 = getelementptr inbounds i8, i8* %30, i64 1
%34 = load i8, i8* %33
br label %15
35: ; preds = %15, %20
store i8 0, i8* %12
%36 = ptrtoint i8* %19 to i64
%37 = ptrtoint i8* %9 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = tail call i32 @strncat(i8* %12, i8* %9, i32 %39)
%41 = tail call i32 @strcat(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%42 = tail call i32 @strcat(i8* %12, i8* %19)
%43 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
store i8* %0, i8** %43
%44 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %44
%45 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
store i8* %12, i8** %45
%46 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
store i8* null, i8** %46
%47 = call i32 @execvp(i8* %0, i8** %43)
ret void
}