#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*/ CmdEquation(int);
int /*<<< orphan*/ ConvertString(char *);
int /*<<< orphan*/ diagnostics(int, char *, ...);
int /*<<< orphan*/ free(char *);
char *getBraceParam();
int getTexMode();
void CmdEnsuremath(int code) {
  int mode = getTexMode();
  diagnostics(4, "Entering CmdEnsuremath");
  if (mode == 4 || mode == 5) {
    char *eq = getBraceParam();
    diagnostics(4, "already in math mode <%s>", eq);
    ConvertString(eq);
    free(eq);
  } else {
    diagnostics(4, "need to start new equation");
    CmdEquation(16);
  }
}


x86 assembly (clang, -O0):
<CmdEnsuremath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getTexMode@plt>
mov    %eax,-0x8(%rbp)
mov    $0x4,%edi
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1070 <diagnostics@plt>
cmpl   $0x4,-0x8(%rbp)
je     119c <CmdEnsuremath+0x3c>
cmpl   $0x5,-0x8(%rbp)
jne    11d5 <CmdEnsuremath+0x75>
mov    $0x0,%al
call   1050 <getBraceParam@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
mov    $0x4,%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1070 <diagnostics@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ConvertString@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    11f2 <CmdEnsuremath+0x92>
mov    $0x4,%edi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1070 <diagnostics@plt>
mov    $0x10,%edi
call   1080 <CmdEquation@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CmdEnsuremath>:
push   %rbx
xor    %eax,%eax
call   1040 <getTexMode@plt>
mov    %eax,%ebx
lea    0xe8f(%rip),%rsi
mov    $0x4,%edi
xor    %eax,%eax
call   1070 <diagnostics@plt>
and    $0xfffffffe,%ebx
cmp    $0x4,%ebx
jne    11b6 <CmdEnsuremath+0x56>
xor    %eax,%eax
call   1050 <getBraceParam@plt>
mov    %rax,%rbx
lea    0xe81(%rip),%rsi
mov    $0x4,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <diagnostics@plt>
mov    %rbx,%rdi
call   1060 <ConvertString@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <free@plt>
lea    0xe74(%rip),%rsi
mov    $0x4,%edi
xor    %eax,%eax
call   1070 <diagnostics@plt>
mov    $0x10,%edi
pop    %rbx
jmp    1080 <CmdEquation@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Entering CmdEnsuremath\00"
@.str.1 = [26 x i8] c"already in math mode <%s>\00"
@.str.2 = [27 x i8] c"need to start new equation\00"
define void @CmdEnsuremath(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
%5 = call i32 (...) @getTexMode()
store i32 %5, i32* %3
%6 = call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 4
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 5
br i1 %11, label %12, label %20
12: ; preds = %9, %1
%13 = call i8* (...) @getBraceParam()
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %4
%17 = call i32 @ConvertString(i8* %16)
%18 = load i8*, i8** %4
%19 = call i32 @free(i8* %18)
br label %23
20: ; preds = %9
%21 = call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @CmdEquation(i32 16)
br label %23
23: ; preds = %20, %12
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Entering CmdEnsuremath\00"
@.str.1 = [26 x i8] c"already in math mode <%s>\00"
@.str.2 = [27 x i8] c"need to start new equation\00"
define void @CmdEnsuremath(i32 %0) {
%2 = tail call i32 (...) @getTexMode()
%3 = tail call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = and i32 %2, -2
%5 = icmp eq i32 %4, 4
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = tail call i8* (...) @getBraceParam()
%8 = tail call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = tail call i32 @ConvertString(i8* %7)
%10 = tail call i32 @free(i8* %7)
br label %14
11: ; preds = %1
%12 = tail call i32 (i32, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @CmdEquation(i32 16)
br label %14
14: ; preds = %11, %6
ret void
}