#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 *AddCR(char *);
int IntOrError(int, char **, int);
char *JoinWithSpaces(int, char **);
int Os9Fork(char *, char const *, int /*<<< orphan*/, int /*<<< orphan*/, int,
            int *);
scalar_t__ Tcl_StringMatch(char *, char *);
char Up(char);
int atoi(char *);
int /*<<< orphan*/ free(char *);
int picolArityErr(char *);
int /*<<< orphan*/ strlen(char const *);
int picolCommand9Fork(int argc, char **argv, void *pd) {
  int mem_size = 0;
  while (argc > 2 && Tcl_StringMatch(argv[1], "-m*")) {
    mem_size = atoi(argv[1] + 2);
    if (Up(argv[1][strlen(argv[1]) - 1]) == 'K')
      mem_size <<= 2;
    argc--;
    argv++;
  }
  if (argc < 2) {
    return picolArityErr(argv[0]);
  }
  char *program = argv[1];
  const char *params = JoinWithSpaces(argc - 2, argv + 2);
  params = AddCR((char *)params);
  int child_id = 0;
  int e = Os9Fork(program, params, strlen(params), 0, mem_size, &child_id);
  free((char *)params);
  return IntOrError(e, argv + 1, child_id);
}


x86 assembly (clang, -O0):
<picolCommand9Fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x2,-0x8(%rbp)
mov    %al,-0x39(%rbp)
jle    11e7 <picolCommand9Fork+0x47>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe28(%rip),%rsi
call   1050 <Tcl_StringMatch@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11f7 <picolCommand9Fork+0x57>
jmp    1268 <picolCommand9Fork+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
add    $0x2,%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1090 <Up@plt>
movsbl %al,%eax
cmp    $0x4b,%eax
jne    124e <picolCommand9Fork+0xae>
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11ba <picolCommand9Fork+0x1a>
cmpl   $0x2,-0x8(%rbp)
jge    1286 <picolCommand9Fork+0xe6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <picolArityErr@plt>
mov    %eax,-0x4(%rbp)
jmp    1311 <picolCommand9Fork+0x171>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   10c0 <JoinWithSpaces@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <AddCR@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
mov    -0x1c(%rbp),%r8d
xor    %ecx,%ecx
lea    -0x34(%rbp),%r9
call   1080 <Os9Fork@plt>
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
mov    -0x34(%rbp),%edx
call   1040 <IntOrError@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<picolCommand9Fork>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%ebp
cmp    $0x3,%edi
jl     122a <picolCommand9Fork+0x8a>
mov    0x8(%r12),%rdi
lea    0xe3f(%rip),%rsi
call   1050 <Tcl_StringMatch@plt>
test   %rax,%rax
je     1250 <picolCommand9Fork+0xb0>
add    $0x8,%r12
lea    0xe26(%rip),%r14
mov    %r12,%rbx
nopl   (%rax)
mov    %rbx,%r12
mov    (%rbx),%rbx
lea    0x2(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
movsbl -0x1(%rax,%rbx,1),%edi
call   1090 <Up@plt>
mov    %eax,%r13d
cmp    $0x3,%ebp
jle    1255 <picolCommand9Fork+0xb5>
lea    0x8(%r12),%rbx
mov    0x8(%r12),%rdi
mov    %r14,%rsi
call   1050 <Tcl_StringMatch@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    11e0 <picolCommand9Fork+0x40>
jmp    125a <picolCommand9Fork+0xba>
cmp    $0x2,%ebp
jne    1239 <picolCommand9Fork+0x99>
mov    $0x2,%ebp
xor    %r14d,%r14d
jmp    126a <picolCommand9Fork+0xca>
mov    (%r12),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <picolArityErr@plt>
xor    %r14d,%r14d
jmp    126a <picolCommand9Fork+0xca>
mov    $0x2,%ebp
lea    0x0(,%r15,4),%r14d
cmp    $0x4b,%r13b
cmovne %r15d,%r14d
lea    0x8(%r12),%r15
mov    0x8(%r12),%rbx
add    $0xfffffffe,%ebp
add    $0x10,%r12
mov    %ebp,%edi
mov    %r12,%rsi
call   10c0 <JoinWithSpaces@plt>
mov    %rax,%rdi
call   1060 <AddCR@plt>
mov    %rax,%rbp
movl   $0x0,0x4(%rsp)
mov    %rax,%rdi
call   1070 <strlen@plt>
lea    0x4(%rsp),%r9
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14d,%r8d
call   1080 <Os9Fork@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%edx
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <IntOrError@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"-m*\00"
define i32 @picolCommand9Fork(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i32 0, i32* %8
br label %13
13: ; preds = %47, %3
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, 2
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i8**, i8*** %6
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @Tcl_StringMatch(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br label %22
22: ; preds = %16, %13
%23 = phi i1 [ false, %13 ], [ %21, %16 ]
br i1 %23, label %24, label %52
24: ; preds = %22
%25 = load i8**, i8*** %6
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 2
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %8
%30 = load i8**, i8*** %6
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %6
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strlen(i8* %35)
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %32, i64 %38
%40 = load i8, i8* %39
%41 = call signext i8 @Up(i8 signext %40)
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 75
br i1 %43, label %44, label %47
44: ; preds = %24
%45 = load i32, i32* %8
%46 = shl i32 %45, 2
store i32 %46, i32* %8
br label %47
47: ; preds = %44, %24
%48 = load i32, i32* %5
%49 = add nsw i32 %48, -1
store i32 %49, i32* %5
%50 = load i8**, i8*** %6
%51 = getelementptr inbounds i8*, i8** %50, i32 1
store i8** %51, i8*** %6
br label %13
52: ; preds = %22
%53 = load i32, i32* %5
%54 = icmp slt i32 %53, 2
br i1 %54, label %55, label %60
55: ; preds = %52
%56 = load i8**, i8*** %6
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = call i32 @picolArityErr(i8* %58)
store i32 %59, i32* %4
br label %84
60: ; preds = %52
%61 = load i8**, i8*** %6
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
store i8* %63, i8** %9
%64 = load i32, i32* %5
%65 = sub nsw i32 %64, 2
%66 = load i8**, i8*** %6
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = call i8* @JoinWithSpaces(i32 %65, i8** %67)
store i8* %68, i8** %10
%69 = load i8*, i8** %10
%70 = call i8* @AddCR(i8* %69)
store i8* %70, i8** %10
store i32 0, i32* %11
%71 = load i8*, i8** %9
%72 = load i8*, i8** %10
%73 = load i8*, i8** %10
%74 = call i32 @strlen(i8* %73)
%75 = load i32, i32* %8
%76 = call i32 @Os9Fork(i8* %71, i8* %72, i32 %74, i32 0, i32 %75, i32* %11)
store i32 %76, i32* %12
%77 = load i8*, i8** %10
%78 = call i32 @free(i8* %77)
%79 = load i32, i32* %12
%80 = load i8**, i8*** %6
%81 = getelementptr inbounds i8*, i8** %80, i64 1
%82 = load i32, i32* %11
%83 = call i32 @IntOrError(i32 %79, i8** %81, i32 %82)
store i32 %83, i32* %4
br label %84
84: ; preds = %60, %55
%85 = load i32, i32* %4
ret i32 %85
}

LLVM IR (-O2):
@.str = [4 x i8] c"-m*\00"
define i32 @picolCommand9Fork(i32 %0, i8** %1, i8* nocapture readnone %2) {
%4 = alloca i32
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %30
6: ; preds = %3
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @Tcl_StringMatch(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %40, label %16
11: ; preds = %16
%12 = getelementptr inbounds i8*, i8** %17, i64 1
%13 = load i8*, i8** %12
%14 = tail call i64 @Tcl_StringMatch(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %35, label %16
16: ; preds = %6, %11
%17 = phi i8** [ %12, %11 ], [ %7, %6 ]
%18 = phi i32 [ %28, %11 ], [ %0, %6 ]
%19 = load i8*, i8** %17
%20 = getelementptr inbounds i8, i8* %19, i64 2
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i32 @strlen(i8* %19)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %19, i64 %24
%26 = load i8, i8* %25
%27 = tail call signext i8 @Up(i8 signext %26)
%28 = add nsw i32 %18, -1
%29 = icmp sgt i32 %18, 3
br i1 %29, label %11, label %35
30: ; preds = %3
%31 = icmp eq i32 %0, 2
br i1 %31, label %40, label %32
32: ; preds = %30
%33 = load i8*, i8** %1
%34 = tail call i32 @picolArityErr(i8* %33)
br label %56
35: ; preds = %16, %11
%36 = phi i32 [ 2, %16 ], [ %28, %11 ]
%37 = icmp eq i8 %27, 75
%38 = shl i32 %21, 2
%39 = select i1 %37, i32 %38, i32 %21
br label %40
40: ; preds = %35, %6, %30
%41 = phi i32 [ 0, %30 ], [ 0, %6 ], [ %39, %35 ]
%42 = phi i8** [ %1, %30 ], [ %1, %6 ], [ %17, %35 ]
%43 = phi i32 [ 2, %30 ], [ %0, %6 ], [ %36, %35 ]
%44 = getelementptr inbounds i8*, i8** %42, i64 1
%45 = load i8*, i8** %44
%46 = add nsw i32 %43, -2
%47 = getelementptr inbounds i8*, i8** %42, i64 2
%48 = tail call i8* @JoinWithSpaces(i32 %46, i8** %47)
%49 = tail call i8* @AddCR(i8* %48)
%50 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%51 = tail call i32 @strlen(i8* %49)
%52 = call i32 @Os9Fork(i8* %45, i8* %49, i32 %51, i32 0, i32 %41, i32* %4)
%53 = call i32 @free(i8* %49)
%54 = load i32, i32* %4
%55 = call i32 @IntOrError(i32 %52, i8** %44, i32 %54)
br label %56
56: ; preds = %40, %32
%57 = phi i32 [ %34, %32 ], [ %55, %40 ]
ret i32 %57
}