#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 /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *getSimpleCommand();
char getTexChar();
char *my_strdup(char *);
int /*<<< orphan*/ my_strlcat(char *, char *, int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ ungetTexChar(char);
char *getLeftRightParam(void) {
  char text[5000], s, *command;
  int i = 0;
  int lrdepth = 1;
  text[0] = '\0';
  for (;;) {
    s = getTexChar();
    if (s == '\\') {
      ungetTexChar(s);
      command = getSimpleCommand();
      if (strcmp(command, "\\right") == 0) {
        lrdepth--;
        if (lrdepth == 0) {
          free(command);
          return my_strdup(text);
        }
      }
      my_strlcat(text + i, command, 5000);
      i += (int)strlen(command);
      if (i > 4950)
        diagnostics(0, "Contents of \\left .. \\right too large.");
      if (strcmp(command, "\\left") == 0)
        lrdepth++;
      free(command);
    } else {
      text[i] = s;
      i++;
      text[i] = '\0';
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getLeftRightParam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13b0,%rsp
movl   $0x0,-0x13a4(%rbp)
movl   $0x1,-0x13a8(%rbp)
movb   $0x0,-0x1390(%rbp)
mov    $0x0,%al
call   1060 <getTexChar@plt>
mov    %al,-0x1391(%rbp)
movsbl -0x1391(%rbp),%eax
cmp    $0x5c,%eax
jne    12e1 <getLeftRightParam+0x151>
movsbl -0x1391(%rbp),%edi
call   1040 <ungetTexChar@plt>
mov    $0x0,%al
call   10b0 <getSimpleCommand@plt>
mov    %rax,-0x13a0(%rbp)
mov    -0x13a0(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    124c <getLeftRightParam+0xbc>
mov    -0x13a8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x13a8(%rbp)
cmpl   $0x0,-0x13a8(%rbp)
jne    1247 <getLeftRightParam+0xb7>
mov    -0x13a0(%rbp),%rdi
call   1030 <free@plt>
lea    -0x1390(%rbp),%rdi
call   10a0 <my_strdup@plt>
add    $0x13b0,%rsp
pop    %rbp
ret
jmp    124c <getLeftRightParam+0xbc>
lea    -0x1390(%rbp),%rdi
movslq -0x13a4(%rbp),%rax
add    %rax,%rdi
mov    -0x13a0(%rbp),%rsi
mov    $0x1388,%edx
call   1050 <my_strlcat@plt>
mov    -0x13a0(%rbp),%rdi
call   1070 <strlen@plt>
add    -0x13a4(%rbp),%eax
mov    %eax,-0x13a4(%rbp)
cmpl   $0x1356,-0x13a4(%rbp)
jle    12a4 <getLeftRightParam+0x114>
xor    %edi,%edi
lea    0xd68(%rip),%rsi
call   1080 <diagnostics@plt>
mov    -0x13a0(%rbp),%rdi
lea    0xd7c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12d0 <getLeftRightParam+0x140>
mov    -0x13a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13a8(%rbp)
mov    -0x13a0(%rbp),%rdi
call   1030 <free@plt>
jmp    1313 <getLeftRightParam+0x183>
mov    -0x1391(%rbp),%cl
movslq -0x13a4(%rbp),%rax
mov    %cl,-0x1390(%rbp,%rax,1)
mov    -0x13a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13a4(%rbp)
movslq -0x13a4(%rbp),%rax
movb   $0x0,-0x1390(%rbp,%rax,1)
jmp    11b6 <getLeftRightParam+0x26>

x86 assembly (clang, -O2):
<getLeftRightParam>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1388,%rsp
movb   $0x0,(%rsp)
mov    $0x1,%ebp
lea    0xe4f(%rip),%r15
lea    0xe76(%rip),%r12
xor    %ebx,%ebx
jmp    11da <getLeftRightParam+0x4a>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r12,%rsi
call   1090 <strcmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebp
mov    %r13,%rdi
call   1030 <free@plt>
movslq %ebx,%r14
nopl   (%rax)
xor    %eax,%eax
call   1060 <getTexChar@plt>
cmp    $0x5c,%al
je     1200 <getLeftRightParam+0x70>
mov    %al,(%rsp,%r14,1)
add    $0x1,%r14
movslq %r14d,%rax
movb   $0x0,(%rsp,%rax,1)
jmp    11e0 <getLeftRightParam+0x50>
nopl   0x0(%rax)
mov    $0x5c,%edi
call   1040 <ungetTexChar@plt>
xor    %eax,%eax
call   10b0 <getSimpleCommand@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    1229 <getLeftRightParam+0x99>
add    $0xffffffff,%ebp
je     1267 <getLeftRightParam+0xd7>
lea    (%rsp,%r14,1),%rdi
mov    %r13,%rsi
mov    $0x1388,%edx
call   1050 <my_strlcat@plt>
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbx
add    %r14,%rbx
cmp    $0x1357,%ebx
jl     11c0 <getLeftRightParam+0x30>
xor    %edi,%edi
lea    0xdaa(%rip),%rsi
call   1080 <diagnostics@plt>
jmp    11c0 <getLeftRightParam+0x30>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rsp,%rdi
call   10a0 <my_strdup@plt>
add    $0x1388,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\\right\00"
@.str.1 = [39 x i8] c"Contents of \\left .. \\right too large.\00"
@.str.2 = [6 x i8] c"\\left\00"
define i8* @getLeftRightParam() {
%1 = alloca [5000 x i8]
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %4
store i32 1, i32* %5
%6 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 0
store i8 0, i8* %6
br label %7
7: ; preds = %66, %0
%8 = call signext i8 (...) @getTexChar()
store i8 %8, i8* %2
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 92
br i1 %11, label %12, label %56
12: ; preds = %7
%13 = load i8, i8* %2
%14 = call i32 @ungetTexChar(i8 signext %13)
%15 = call i8* (...) @getSimpleCommand()
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %12
%20 = load i32, i32* %5
%21 = add nsw i32 %20, -1
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = call i32 @free(i8* %25)
%27 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 0
%28 = call i8* @my_strdup(i8* %27)
ret i8* %28
29: ; preds = %19
br label %30
30: ; preds = %29, %12
%31 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 0
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8*, i8** %3
%36 = call i32 @my_strlcat(i8* %34, i8* %35, i32 5000)
%37 = load i8*, i8** %3
%38 = call i64 @strlen(i8* %37)
%39 = trunc i64 %38 to i32
%40 = load i32, i32* %4
%41 = add nsw i32 %40, %39
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = icmp sgt i32 %42, 4950
br i1 %43, label %44, label %46
44: ; preds = %30
%45 = call i32 @diagnostics(i32 0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %44, %30
%47 = load i8*, i8** %3
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %46
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %53
53: ; preds = %50, %46
%54 = load i8*, i8** %3
%55 = call i32 @free(i8* %54)
br label %66
56: ; preds = %7
%57 = load i8, i8* %2
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %59
store i8 %57, i8* %60
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
%63 = load i32, i32* %4
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %64
store i8 0, i8* %65
br label %66
66: ; preds = %56, %53
br label %7
}

LLVM IR (-O2):
@.str = [7 x i8] c"\\right\00"
@.str.1 = [39 x i8] c"Contents of \\left .. \\right too large.\00"
@.str.2 = [6 x i8] c"\\left\00"
define i8* @getLeftRightParam() {
%1 = alloca [5000 x i8]
%2 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 0
store i8 0, i8* %2
br label %3
3: ; preds = %32, %0
%4 = phi i32 [ %28, %32 ], [ 0, %0 ]
%5 = phi i32 [ %36, %32 ], [ 1, %0 ]
br label %6
6: ; preds = %3, %38
%7 = phi i32 [ %41, %38 ], [ %4, %3 ]
%8 = call signext i8 (...) @getTexChar()
%9 = icmp eq i8 %8, 92
br i1 %9, label %10, label %38
10: ; preds = %6
%11 = call i32 @ungetTexChar(i8 signext 92)
%12 = call i8* (...) @getSimpleCommand()
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = add nsw i32 %5, -1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @free(i8* %12)
%20 = call i8* @my_strdup(i8* %2)
ret i8* %20
21: ; preds = %15, %10
%22 = phi i32 [ %16, %15 ], [ %5, %10 ]
%23 = sext i32 %7 to i64
%24 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %23
%25 = call i32 @my_strlcat(i8* %24, i8* %12, i32 5000)
%26 = call i64 @strlen(i8* dereferenceable(1) %12)
%27 = trunc i64 %26 to i32
%28 = add nsw i32 %7, %27
%29 = icmp sgt i32 %28, 4950
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @diagnostics(i32 0, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %21
%33 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
%35 = zext i1 %34 to i32
%36 = add nsw i32 %22, %35
%37 = call i32 @free(i8* %12)
br label %3
38: ; preds = %6
%39 = sext i32 %7 to i64
%40 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %39
store i8 %8, i8* %40
%41 = add nsw i32 %7, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %42
store i8 0, i8* %43
br label %6
}