#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*/ diagnostics(int, char *, ...);
int /*<<< orphan*/ free(char *);
char *getBraceParam();
int getDimension();
int getLength(char *);
char getNonSpace();
char getTexChar();
int /*<<< orphan*/ setLength(char *, int);
int /*<<< orphan*/ skipSpaces();
int strlen(char *);
int /*<<< orphan*/ ungetTexChar(char);
void CmdLength(int code) {
  char *s, *s1;
  char cThis;
  int num;
  if (code == 3 || code == 2 || code == 1) {
    s = getBraceParam();
    if (strlen(s) <= 1) {
      free(s);
      diagnostics(
          1, "missing argument in \\newlength \\addtolength or \\setlength");
      return;
    }
    s1 = s + 1;
    diagnostics(4, "Entering CmdLength(), <%s>", s1);
    if (code == 3 || code == 2) {
      cThis = getNonSpace();
      if (cThis == '{') {
        num = getDimension();
        diagnostics(4, "size is <%d> twips", num);
        cThis = getTexChar();
        while (cThis && cThis != '}')
          cThis = getTexChar();
        if (code == 3)
          setLength(s1, getLength(s1) + num);
        else
          setLength(s1, num);
      } else
        diagnostics(1, "bad parameter to \\addtolength or \\setlength");
    } else
      setLength(s1, 0);
    free(s);
  } else {
    skipSpaces();
    cThis = getTexChar();
    if (cThis == '=')
      skipSpaces();
    else
      ungetTexChar(cThis);
    getDimension();
  }
}


x86 assembly (clang, -O0):
<CmdLength>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     11d9 <CmdLength+0x29>
cmpl   $0x2,-0x4(%rbp)
je     11d9 <CmdLength+0x29>
cmpl   $0x1,-0x4(%rbp)
jne    133d <CmdLength+0x18d>
mov    $0x0,%al
call   1080 <getBraceParam@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
cmp    $0x1,%eax
jg     1217 <CmdLength+0x67>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
mov    $0x1,%edi
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
jmp    1377 <CmdLength+0x1c7>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
mov    $0x4,%edi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
cmpl   $0x3,-0x4(%rbp)
je     124e <CmdLength+0x9e>
cmpl   $0x2,-0x4(%rbp)
jne    1324 <CmdLength+0x174>
mov    $0x0,%al
call   10a0 <getNonSpace@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x7b,%eax
jne    130c <CmdLength+0x15c>
mov    $0x0,%al
call   10b0 <getDimension@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edx
mov    $0x4,%edi
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
mov    $0x0,%al
call   1060 <getTexChar@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     12ae <CmdLength+0xfe>
movsbl -0x19(%rbp),%eax
cmp    $0x7d,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    12be <CmdLength+0x10e>
jmp    12cd <CmdLength+0x11d>
mov    $0x0,%al
call   1060 <getTexChar@plt>
mov    %al,-0x19(%rbp)
jmp    128f <CmdLength+0xdf>
cmpl   $0x3,-0x4(%rbp)
jne    12fb <CmdLength+0x14b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   10d0 <getLength@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
add    -0x20(%rbp),%esi
call   1030 <setLength@plt>
jmp    1307 <CmdLength+0x157>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1030 <setLength@plt>
jmp    131f <CmdLength+0x16f>
mov    $0x1,%edi
lea    0xd50(%rip),%rsi
mov    $0x0,%al
call   1090 <diagnostics@plt>
jmp    132f <CmdLength+0x17f>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <setLength@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
jmp    1377 <CmdLength+0x1c7>
mov    $0x0,%al
call   10c0 <skipSpaces@plt>
mov    $0x0,%al
call   1060 <getTexChar@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x3d,%eax
jne    1367 <CmdLength+0x1b7>
mov    $0x0,%al
call   10c0 <skipSpaces@plt>
jmp    1370 <CmdLength+0x1c0>
movsbl -0x19(%rbp),%edi
call   1050 <ungetTexChar@plt>
mov    $0x0,%al
call   10b0 <getDimension@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CmdLength>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x1(%rbx),%eax
cmp    $0x2,%eax
ja     11fd <CmdLength+0x4d>
xor    %eax,%eax
call   1080 <getBraceParam@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <strlen@plt>
cmp    $0x1,%eax
jg     121f <CmdLength+0x6f>
mov    %r14,%rdi
call   1040 <free@plt>
lea    0xe19(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <diagnostics@plt>
xor    %eax,%eax
call   10c0 <skipSpaces@plt>
xor    %eax,%eax
call   1060 <getTexChar@plt>
cmp    $0x3d,%al
jne    1295 <CmdLength+0xe5>
xor    %eax,%eax
call   10c0 <skipSpaces@plt>
jmp    129d <CmdLength+0xed>
mov    %ebx,%ebp
and    $0xfffffffe,%ebp
mov    %r14,%r15
add    $0x1,%r15
lea    0xe08(%rip),%rsi
mov    $0x4,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <diagnostics@plt>
cmp    $0x2,%ebp
jne    12ae <CmdLength+0xfe>
xor    %eax,%eax
call   10a0 <getNonSpace@plt>
cmp    $0x7b,%al
jne    12ba <CmdLength+0x10a>
xor    %eax,%eax
call   10b0 <getDimension@plt>
mov    %eax,%ebp
lea    0xdf4(%rip),%rsi
mov    $0x4,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1090 <diagnostics@plt>
nop
xor    %eax,%eax
call   1060 <getTexChar@plt>
cmp    $0x7d,%al
je     127f <CmdLength+0xcf>
test   %al,%al
jne    1270 <CmdLength+0xc0>
cmp    $0x3,%ebx
jne    128e <CmdLength+0xde>
mov    %r15,%rdi
call   10d0 <getLength@plt>
add    %eax,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
jmp    12b3 <CmdLength+0x103>
movsbl %al,%edi
call   1050 <ungetTexChar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <getDimension@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <setLength@plt>
jmp    12cd <CmdLength+0x11d>
lea    0xda7(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1090 <diagnostics@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free@plt>

LLVM IR (-O0):
@.str = [58 x i8] c"missing argument in \\newlength \\addtolength or \\setlength\00"
@.str.1 = [27 x i8] c"Entering CmdLength(), <%s>\00"
@.str.2 = [19 x i8] c"size is <%d> twips\00"
@.str.3 = [44 x i8] c"bad parameter to \\addtolength or \\setlength\00"
define void @CmdLength(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 3
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 2
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %80
15: ; preds = %12, %9, %1
%16 = call i8* (...) @getBraceParam()
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = icmp sle i32 %18, 1
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = call i32 @free(i8* %21)
%23 = call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
br label %93
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %2
%30 = icmp eq i32 %29, 3
br i1 %30, label %34, label %31
31: ; preds = %24
%32 = load i32, i32* %2
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %74
34: ; preds = %31, %24
%35 = call signext i8 (...) @getNonSpace()
store i8 %35, i8* %5
%36 = load i8, i8* %5
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 123
br i1 %38, label %39, label %71
39: ; preds = %34
%40 = call i32 (...) @getDimension()
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = call signext i8 (...) @getTexChar()
store i8 %43, i8* %5
br label %44
44: ; preds = %54, %39
%45 = load i8, i8* %5
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i8, i8* %5
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 125
br label %52
52: ; preds = %48, %44
%53 = phi i1 [ false, %44 ], [ %51, %48 ]
br i1 %53, label %54, label %56
54: ; preds = %52
%55 = call signext i8 (...) @getTexChar()
store i8 %55, i8* %5
br label %44
56: ; preds = %52
%57 = load i32, i32* %2
%58 = icmp eq i32 %57, 3
br i1 %58, label %59, label %66
59: ; preds = %56
%60 = load i8*, i8** %4
%61 = load i8*, i8** %4
%62 = call i32 @getLength(i8* %61)
%63 = load i32, i32* %6
%64 = add nsw i32 %62, %63
%65 = call i32 @setLength(i8* %60, i32 %64)
br label %70
66: ; preds = %56
%67 = load i8*, i8** %4
%68 = load i32, i32* %6
%69 = call i32 @setLength(i8* %67, i32 %68)
br label %70
70: ; preds = %66, %59
br label %73
71: ; preds = %34
%72 = call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %73
73: ; preds = %71, %70
br label %77
74: ; preds = %31
%75 = load i8*, i8** %4
%76 = call i32 @setLength(i8* %75, i32 0)
br label %77
77: ; preds = %74, %73
%78 = load i8*, i8** %3
%79 = call i32 @free(i8* %78)
br label %93
80: ; preds = %12
%81 = call i32 (...) @skipSpaces()
%82 = call signext i8 (...) @getTexChar()
store i8 %82, i8* %5
%83 = load i8, i8* %5
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 61
br i1 %85, label %86, label %88
86: ; preds = %80
%87 = call i32 (...) @skipSpaces()
br label %91
88: ; preds = %80
%89 = load i8, i8* %5
%90 = call i32 @ungetTexChar(i8 signext %89)
br label %91
91: ; preds = %88, %86
%92 = call i32 (...) @getDimension()
br label %93
93: ; preds = %20, %91, %77
ret void
}

LLVM IR (-O2):
@.str = [58 x i8] c"missing argument in \\newlength \\addtolength or \\setlength\00"
@.str.1 = [27 x i8] c"Entering CmdLength(), <%s>\00"
@.str.2 = [19 x i8] c"size is <%d> twips\00"
@.str.3 = [44 x i8] c"bad parameter to \\addtolength or \\setlength\00"
define void @CmdLength(i32 %0) {
%2 = icmp eq i32 %0, 3
%3 = and i32 %0, -2
%4 = icmp eq i32 %3, 2
%5 = add i32 %0, -1
%6 = icmp ult i32 %5, 3
br i1 %6, label %7, label %38
7: ; preds = %1
%8 = tail call i8* (...) @getBraceParam()
%9 = tail call i32 @strlen(i8* %8)
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @free(i8* %8)
%13 = tail call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
br label %48
14: ; preds = %7
%15 = getelementptr inbounds i8, i8* %8, i64 1
%16 = tail call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br i1 %4, label %17, label %34
17: ; preds = %14
%18 = tail call signext i8 (...) @getNonSpace()
%19 = icmp eq i8 %18, 123
br i1 %19, label %20, label %32
20: ; preds = %17
%21 = tail call i32 (...) @getDimension()
%22 = tail call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %23, %20
%24 = tail call signext i8 (...) @getTexChar()
switch i8 %24, label %23 [
i8 125, label %25
i8 0, label %25
]
25: ; preds = %23, %23
br i1 %2, label %26, label %30
26: ; preds = %25
%27 = tail call i32 @getLength(i8* %15)
%28 = add nsw i32 %27, %21
%29 = tail call i32 @setLength(i8* %15, i32 %28)
br label %36
30: ; preds = %25
%31 = tail call i32 @setLength(i8* %15, i32 %21)
br label %36
32: ; preds = %17
%33 = tail call i32 (i32, i8*, ...) @diagnostics(i32 1, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %36
34: ; preds = %14
%35 = tail call i32 @setLength(i8* %15, i32 0)
br label %36
36: ; preds = %32, %30, %26, %34
%37 = tail call i32 @free(i8* %8)
br label %48
38: ; preds = %1
%39 = tail call i32 (...) @skipSpaces()
%40 = tail call signext i8 (...) @getTexChar()
%41 = icmp eq i8 %40, 61
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = tail call i32 (...) @skipSpaces()
br label %46
44: ; preds = %38
%45 = tail call i32 @ungetTexChar(i8 signext %40)
br label %46
46: ; preds = %44, %42
%47 = tail call i32 (...) @getDimension()
br label %48
48: ; preds = %36, %46, %11
ret void
}