#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*/ UpdateLineNumber(char *);
int /*<<< orphan*/ diagnostics(int, char *, ...);
int /*<<< orphan*/ free(char *);
char *getBraceParam();
char *getBracketParam();
int /*<<< orphan*/ newEnvironment(char *, char *, char *, char *, int);
int /*<<< orphan*/ renewEnvironment(char *, char *, char *, char *, int);
void CmdNewEnvironment(int code) {
  char *name, *opt_param, *begdef, *enddef, *params;
  int param;
  name = getBraceParam();
  params = getBracketParam();
  opt_param = getBracketParam();
  begdef = getBraceParam();
  enddef = getBraceParam();
  UpdateLineNumber(name);
  UpdateLineNumber(params);
  if (opt_param)
    UpdateLineNumber(opt_param);
  UpdateLineNumber(begdef);
  UpdateLineNumber(enddef);
  param = 0;
  if (params) {
    if ('0' <= *params && *params <= '9')
      param = *params - '0';
    else
      diagnostics(0, "non-numeric number of parameters in newcommand");
  }
  diagnostics(2, "CmdNewEnvironment name=<%s> param=%d", name, param);
  diagnostics(2, "CmdNewEnvironment begdef=<%s>", begdef);
  diagnostics(2, "CmdNewEnvironment enddef=<%s>", enddef);
  if (code == 1)
    newEnvironment(name, opt_param, begdef, enddef, param);
  else
    renewEnvironment(name, opt_param, begdef, enddef, param);
  if (opt_param)
    free(opt_param);
  free(name);
  free(begdef);
  free(enddef);
  if (params)
    free(params);
}


x86 assembly (clang, -O0):
<CmdNewEnvironment>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getBraceParam@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1080 <getBracketParam@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <getBracketParam@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getBraceParam@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getBraceParam@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <UpdateLineNumber@plt>
mov    -0x30(%rbp),%rdi
call   1090 <UpdateLineNumber@plt>
cmpq   $0x0,-0x18(%rbp)
je     11d8 <CmdNewEnvironment+0x68>
mov    -0x18(%rbp),%rdi
call   1090 <UpdateLineNumber@plt>
mov    -0x20(%rbp),%rdi
call   1090 <UpdateLineNumber@plt>
mov    -0x28(%rbp),%rdi
call   1090 <UpdateLineNumber@plt>
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1247 <CmdNewEnvironment+0xd7>
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     1232 <CmdNewEnvironment+0xc2>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     1232 <CmdNewEnvironment+0xc2>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x34(%rbp)
jmp    1242 <CmdNewEnvironment+0xd2>
xor    %edi,%edi
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1050 <diagnostics@plt>
jmp    1247 <CmdNewEnvironment+0xd7>
mov    -0x10(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    $0x2,%edi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1050 <diagnostics@plt>
mov    -0x20(%rbp),%rdx
mov    $0x2,%edi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1050 <diagnostics@plt>
mov    -0x28(%rbp),%rdx
mov    $0x2,%edi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1050 <diagnostics@plt>
cmpl   $0x1,-0x4(%rbp)
jne    12b7 <CmdNewEnvironment+0x147>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x34(%rbp),%r8d
call   1070 <newEnvironment@plt>
jmp    12d0 <CmdNewEnvironment+0x160>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x34(%rbp),%r8d
call   1060 <renewEnvironment@plt>
cmpq   $0x0,-0x18(%rbp)
je     12e4 <CmdNewEnvironment+0x174>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     1313 <CmdNewEnvironment+0x1a3>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CmdNewEnvironment>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,0x4(%rsp)
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getBraceParam@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1080 <getBracketParam@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <getBracketParam@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getBraceParam@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1040 <getBraceParam@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1090 <UpdateLineNumber@plt>
mov    %r15,%rdi
call   1090 <UpdateLineNumber@plt>
test   %rbx,%rbx
je     11d0 <CmdNewEnvironment+0x60>
mov    %rbx,%rdi
call   1090 <UpdateLineNumber@plt>
mov    %r12,%rdi
call   1090 <UpdateLineNumber@plt>
mov    %r13,%rdi
call   1090 <UpdateLineNumber@plt>
test   %r15,%r15
je     1207 <CmdNewEnvironment+0x97>
movzbl (%r15),%ebp
lea    -0x30(%rbp),%eax
cmp    $0x9,%al
ja     11f5 <CmdNewEnvironment+0x85>
add    $0xffffffd0,%ebp
jmp    1207 <CmdNewEnvironment+0x97>
lea    0xe04(%rip),%rsi
xor    %ebp,%ebp
xor    %edi,%edi
xor    %eax,%eax
call   1050 <diagnostics@plt>
lea    0xe21(%rip),%rsi
mov    $0x2,%edi
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <diagnostics@plt>
lea    0xe2e(%rip),%rsi
mov    $0x2,%edi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <diagnostics@plt>
lea    0xe36(%rip),%rsi
mov    $0x2,%edi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <diagnostics@plt>
cmpl   $0x1,0x4(%rsp)
jne    126d <CmdNewEnvironment+0xfd>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %ebp,%r8d
call   1070 <newEnvironment@plt>
test   %rbx,%rbx
jne    1286 <CmdNewEnvironment+0x116>
jmp    128e <CmdNewEnvironment+0x11e>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %ebp,%r8d
call   1060 <renewEnvironment@plt>
test   %rbx,%rbx
je     128e <CmdNewEnvironment+0x11e>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     12c1 <CmdNewEnvironment+0x151>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"non-numeric number of parameters in newcommand\00"
@.str.1 = [37 x i8] c"CmdNewEnvironment name=<%s> param=%d\00"
@.str.2 = [30 x i8] c"CmdNewEnvironment begdef=<%s>\00"
@.str.3 = [30 x i8] c"CmdNewEnvironment enddef=<%s>\00"
define void @CmdNewEnvironment(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %2
%9 = call i8* (...) @getBraceParam()
store i8* %9, i8** %3
%10 = call i8* (...) @getBracketParam()
store i8* %10, i8** %7
%11 = call i8* (...) @getBracketParam()
store i8* %11, i8** %4
%12 = call i8* (...) @getBraceParam()
store i8* %12, i8** %5
%13 = call i8* (...) @getBraceParam()
store i8* %13, i8** %6
%14 = load i8*, i8** %3
%15 = call i32 @UpdateLineNumber(i8* %14)
%16 = load i8*, i8** %7
%17 = call i32 @UpdateLineNumber(i8* %16)
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %1
%21 = load i8*, i8** %4
%22 = call i32 @UpdateLineNumber(i8* %21)
br label %23
23: ; preds = %20, %1
%24 = load i8*, i8** %5
%25 = call i32 @UpdateLineNumber(i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 @UpdateLineNumber(i8* %26)
store i32 0, i32* %8
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %48
30: ; preds = %23
%31 = load i8*, i8** %7
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp sle i32 48, %33
br i1 %34, label %35, label %45
35: ; preds = %30
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp sle i32 %38, 57
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i8*, i8** %7
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = sub nsw i32 %43, 48
store i32 %44, i32* %8
br label %47
45: ; preds = %35, %30
%46 = call i32 (i32, i8*, ...) @diagnostics(i32 0, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %47
47: ; preds = %45, %40
br label %48
48: ; preds = %47, %23
%49 = load i8*, i8** %3
%50 = load i32, i32* %8
%51 = call i32 (i32, i8*, ...) @diagnostics(i32 2, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %49, i32 %50)
%52 = load i8*, i8** %5
%53 = call i32 (i32, i8*, ...) @diagnostics(i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %52)
%54 = load i8*, i8** %6
%55 = call i32 (i32, i8*, ...) @diagnostics(i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %54)
%56 = load i32, i32* %2
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %65
58: ; preds = %48
%59 = load i8*, i8** %3
%60 = load i8*, i8** %4
%61 = load i8*, i8** %5
%62 = load i8*, i8** %6
%63 = load i32, i32* %8
%64 = call i32 @newEnvironment(i8* %59, i8* %60, i8* %61, i8* %62, i32 %63)
br label %72
65: ; preds = %48
%66 = load i8*, i8** %3
%67 = load i8*, i8** %4
%68 = load i8*, i8** %5
%69 = load i8*, i8** %6
%70 = load i32, i32* %8
%71 = call i32 @renewEnvironment(i8* %66, i8* %67, i8* %68, i8* %69, i32 %70)
br label %72
72: ; preds = %65, %58
%73 = load i8*, i8** %4
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = load i8*, i8** %4
%77 = call i32 @free(i8* %76)
br label %78
78: ; preds = %75, %72
%79 = load i8*, i8** %3
%80 = call i32 @free(i8* %79)
%81 = load i8*, i8** %5
%82 = call i32 @free(i8* %81)
%83 = load i8*, i8** %6
%84 = call i32 @free(i8* %83)
%85 = load i8*, i8** %7
%86 = icmp ne i8* %85, null
br i1 %86, label %87, label %90
87: ; preds = %78
%88 = load i8*, i8** %7
%89 = call i32 @free(i8* %88)
br label %90
90: ; preds = %87, %78
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"non-numeric number of parameters in newcommand\00"
@.str.1 = [37 x i8] c"CmdNewEnvironment name=<%s> param=%d\00"
@.str.2 = [30 x i8] c"CmdNewEnvironment begdef=<%s>\00"
@.str.3 = [30 x i8] c"CmdNewEnvironment enddef=<%s>\00"
define void @CmdNewEnvironment(i32 %0) {
%2 = tail call i8* (...) @getBraceParam()
%3 = tail call i8* (...) @getBracketParam()
%4 = tail call i8* (...) @getBracketParam()
%5 = tail call i8* (...) @getBraceParam()
%6 = tail call i8* (...) @getBraceParam()
%7 = tail call i32 @UpdateLineNumber(i8* %2)
%8 = tail call i32 @UpdateLineNumber(i8* %3)
%9 = icmp eq i8* %4, null
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = tail call i32 @UpdateLineNumber(i8* %4)
br label %12
12: ; preds = %10, %1
%13 = tail call i32 @UpdateLineNumber(i8* %5)
%14 = tail call i32 @UpdateLineNumber(i8* %6)
%15 = icmp eq i8* %3, null
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = load i8, i8* %3
%18 = add i8 %17, -48
%19 = icmp ult i8 %18, 10
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = zext i8 %17 to i32
%22 = add nsw i32 %21, -48
br label %25
23: ; preds = %16
%24 = tail call i32 (i32, i8*, ...) @diagnostics(i32 0, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %20, %23, %12
%26 = phi i32 [ %22, %20 ], [ 0, %23 ], [ 0, %12 ]
%27 = tail call i32 (i32, i8*, ...) @diagnostics(i32 2, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %26)
%28 = tail call i32 (i32, i8*, ...) @diagnostics(i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%29 = tail call i32 (i32, i8*, ...) @diagnostics(i32 2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%30 = icmp eq i32 %0, 1
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = tail call i32 @newEnvironment(i8* %2, i8* %4, i8* %5, i8* %6, i32 %26)
br label %35
33: ; preds = %25
%34 = tail call i32 @renewEnvironment(i8* %2, i8* %4, i8* %5, i8* %6, i32 %26)
br label %35
35: ; preds = %33, %31
br i1 %9, label %38, label %36
36: ; preds = %35
%37 = tail call i32 @free(i8* %4)
br label %38
38: ; preds = %36, %35
%39 = tail call i32 @free(i8* %2)
%40 = tail call i32 @free(i8* %5)
%41 = tail call i32 @free(i8* %6)
br i1 %15, label %44, label %42
42: ; preds = %38
%43 = tail call i32 @free(i8* %3)
br label %44
44: ; preds = %42, %38
ret void
}