#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 *);
char *getSimpleCommand();
char getTexChar();
scalar_t__ malloc(int);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ ungetTexChar(char);
void getDelimOrCommand(char *delim, char **s) {
  *delim = '\0';
  ungetTexChar('\\');
  *s = getSimpleCommand();
  if (strlen(*s) == 1) {
    free(*s);
    *s = (char *)malloc(3 * sizeof(char));
    (*s)[0] = '\\';
    (*s)[1] = getTexChar();
    (*s)[2] = '\0';
  }
  if (*s) {
    if (strcmp(*s, "\\{") == 0 || strcmp(*s, "\\lbrace") == 0)
      *delim = '{';
    if (strcmp(*s, "\\}") == 0 || strcmp(*s, "\\rbrace") == 0)
      *delim = '}';
    if (strcmp(*s, "\\bracevert") == 0)
      *delim = '|';
    if (strcmp(*s, "\\langle") == 0)
      *delim = '<';
    if (strcmp(*s, "\\rangle") == 0) {
      *delim = '>';
    }
    if (*delim) {
      free(*s);
      *s = NULL;
    }
  }
}


x86 assembly (clang, -O0):
<getDelimOrCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x5c,%edi
call   1040 <ungetTexChar@plt>
mov    $0x0,%al
call   1090 <getSimpleCommand@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
cmp    $0x1,%eax
jne    11ff <getDelimOrCommand+0x8f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    $0x3,%edi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movb   $0x5c,(%rax)
mov    $0x0,%al
call   1050 <getTexChar@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,0x2(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1324 <getDelimOrCommand+0x1b4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xde5(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1247 <getDelimOrCommand+0xd7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdcb(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    124e <getDelimOrCommand+0xde>
mov    -0x8(%rbp),%rax
movb   $0x7b,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xdaf(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1288 <getDelimOrCommand+0x118>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd95(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    128f <getDelimOrCommand+0x11f>
mov    -0x8(%rbp),%rax
movb   $0x7d,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd79(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12b3 <getDelimOrCommand+0x143>
mov    -0x8(%rbp),%rax
movb   $0x7c,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd60(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12d7 <getDelimOrCommand+0x167>
mov    -0x8(%rbp),%rax
movb   $0x3c,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd44(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12fb <getDelimOrCommand+0x18b>
mov    -0x8(%rbp),%rax
movb   $0x3e,(%rax)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     131f <getDelimOrCommand+0x1af>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
jmp    1324 <getDelimOrCommand+0x1b4>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDelimOrCommand>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movb   $0x0,(%rdi)
mov    $0x5c,%edi
call   1040 <ungetTexChar@plt>
xor    %eax,%eax
call   1090 <getSimpleCommand@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
call   1060 <strlen@plt>
cmp    $0x1,%eax
jne    11ca <getDelimOrCommand+0x5a>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    $0x3,%edi
call   1080 <malloc@plt>
mov    %rax,(%rbx)
movb   $0x5c,(%rax)
xor    %eax,%eax
call   1050 <getTexChar@plt>
mov    (%rbx),%rcx
mov    %al,0x1(%rcx)
mov    (%rbx),%rax
movb   $0x0,0x2(%rax)
mov    (%rbx),%rdi
test   %rdi,%rdi
je     128a <getDelimOrCommand+0x11a>
lea    0xe23(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11fb <getDelimOrCommand+0x8b>
mov    (%rbx),%rdi
lea    0xe12(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11ff <getDelimOrCommand+0x8f>
movb   $0x7b,(%r14)
mov    (%rbx),%rdi
lea    0xe02(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1227 <getDelimOrCommand+0xb7>
mov    (%rbx),%rdi
lea    0xdf1(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    122b <getDelimOrCommand+0xbb>
movb   $0x7d,(%r14)
mov    (%rbx),%rdi
lea    0xde1(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1243 <getDelimOrCommand+0xd3>
movb   $0x7c,(%r14)
mov    (%rbx),%rdi
lea    0xdd4(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    125b <getDelimOrCommand+0xeb>
movb   $0x3c,(%r14)
mov    (%rbx),%rdi
lea    0xdc4(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1277 <getDelimOrCommand+0x107>
cmpb   $0x0,(%r14)
jne    127b <getDelimOrCommand+0x10b>
jmp    128a <getDelimOrCommand+0x11a>
movb   $0x3e,(%r14)
mov    (%rbx),%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\{\00"
@.str.1 = [8 x i8] c"\\lbrace\00"
@.str.2 = [3 x i8] c"\\}\00"
@.str.3 = [8 x i8] c"\\rbrace\00"
@.str.4 = [11 x i8] c"\\bracevert\00"
@.str.5 = [8 x i8] c"\\langle\00"
@.str.6 = [8 x i8] c"\\rangle\00"
define void @getDelimOrCommand(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
store i8* %0, i8** %3
store i8** %1, i8*** %4
%5 = load i8*, i8** %3
store i8 0, i8* %5
%6 = call i32 @ungetTexChar(i8 signext 92)
%7 = call i8* (...) @getSimpleCommand()
%8 = load i8**, i8*** %4
store i8* %7, i8** %8
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
%11 = call i32 @strlen(i8* %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %30
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = load i8*, i8** %14
%16 = call i32 @free(i8* %15)
%17 = call i64 @malloc(i32 3)
%18 = inttoptr i64 %17 to i8*
%19 = load i8**, i8*** %4
store i8* %18, i8** %19
%20 = load i8**, i8*** %4
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 92, i8* %22
%23 = call signext i8 (...) @getTexChar()
%24 = load i8**, i8*** %4
%25 = load i8*, i8** %24
%26 = getelementptr inbounds i8, i8* %25, i64 1
store i8 %23, i8* %26
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 2
store i8 0, i8* %29
br label %30
30: ; preds = %13, %2
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %89
34: ; preds = %30
%35 = load i8**, i8*** %4
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %44, label %39
39: ; preds = %34
%40 = load i8**, i8*** %4
%41 = load i8*, i8** %40
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %39, %34
%45 = load i8*, i8** %3
store i8 123, i8* %45
br label %46
46: ; preds = %44, %39
%47 = load i8**, i8*** %4
%48 = load i8*, i8** %47
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %56, label %51
51: ; preds = %46
%52 = load i8**, i8*** %4
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %51, %46
%57 = load i8*, i8** %3
store i8 125, i8* %57
br label %58
58: ; preds = %56, %51
%59 = load i8**, i8*** %4
%60 = load i8*, i8** %59
%61 = call i64 @strcmp(i8* %60, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %58
%64 = load i8*, i8** %3
store i8 124, i8* %64
br label %65
65: ; preds = %63, %58
%66 = load i8**, i8*** %4
%67 = load i8*, i8** %66
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %65
%71 = load i8*, i8** %3
store i8 60, i8* %71
br label %72
72: ; preds = %70, %65
%73 = load i8**, i8*** %4
%74 = load i8*, i8** %73
%75 = call i64 @strcmp(i8* %74, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %72
%78 = load i8*, i8** %3
store i8 62, i8* %78
br label %79
79: ; preds = %77, %72
%80 = load i8*, i8** %3
%81 = load i8, i8* %80
%82 = icmp ne i8 %81, 0
br i1 %82, label %83, label %88
83: ; preds = %79
%84 = load i8**, i8*** %4
%85 = load i8*, i8** %84
%86 = call i32 @free(i8* %85)
%87 = load i8**, i8*** %4
store i8* null, i8** %87
br label %88
88: ; preds = %83, %79
br label %89
89: ; preds = %88, %30
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\{\00"
@.str.1 = [8 x i8] c"\\lbrace\00"
@.str.2 = [3 x i8] c"\\}\00"
@.str.3 = [8 x i8] c"\\rbrace\00"
@.str.4 = [11 x i8] c"\\bracevert\00"
@.str.5 = [8 x i8] c"\\langle\00"
@.str.6 = [8 x i8] c"\\rangle\00"
define void @getDelimOrCommand(i8* nocapture %0, i8** nocapture %1) {
store i8 0, i8* %0
%3 = tail call i32 @ungetTexChar(i8 signext 92)
%4 = tail call i8* (...) @getSimpleCommand()
store i8* %4, i8** %1
%5 = tail call i32 @strlen(i8* %4)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @free(i8* %8)
%10 = tail call i64 @malloc(i32 3)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %1
store i8 92, i8* %11
%12 = tail call signext i8 (...) @getTexChar()
%13 = load i8*, i8** %1
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %12, i8* %14
%15 = load i8*, i8** %1
%16 = getelementptr inbounds i8, i8* %15, i64 2
store i8 0, i8* %16
br label %17
17: ; preds = %7, %2
%18 = load i8*, i8** %1
%19 = icmp eq i8* %18, null
br i1 %19, label %58, label %20
20: ; preds = %17
%21 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = load i8*, i8** %1
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23, %20
store i8 123, i8* %0
br label %28
28: ; preds = %27, %23
%29 = load i8*, i8** %1
%30 = tail call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i8*, i8** %1
%34 = tail call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32, %28
store i8 125, i8* %0
br label %37
37: ; preds = %36, %32
%38 = load i8*, i8** %1
%39 = tail call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i8 124, i8* %0
br label %42
42: ; preds = %41, %37
%43 = load i8*, i8** %1
%44 = tail call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
store i8 60, i8* %0
br label %47
47: ; preds = %46, %42
%48 = load i8*, i8** %1
%49 = tail call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %47
store i8 62, i8* %0
br label %55
52: ; preds = %47
%53 = load i8, i8* %0
%54 = icmp eq i8 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %51, %52
%56 = load i8*, i8** %1
%57 = tail call i32 @free(i8* %56)
store i8* null, i8** %1
br label %58
58: ; preds = %52, %55, %17
ret void
}