#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*/ strncpy(char *, char *, int);
char *strdetex(char *s, int mode) {
  static char sbuff[4096];
  int strreplace();
  *sbuff = '\000';
  if (((s) == NULL ? 1 : (*(s) == '\000' ? 1 : 0)))
    goto end_of_job;
  if ((sbuff) != NULL && (2048) >= 0) {
    char *thissource = (s);
    (sbuff)[0] = '\000';
    if ((2048) > 0 && thissource != NULL) {
      strncpy((sbuff), thissource, (2048));
      (sbuff)[(2048)] = '\000';
    }
  };
  strreplace(sbuff, "\\", "\\backslash~\\!\\!", 0);
  strreplace(sbuff, "{", "\\lbrace~\\!\\!", 0);
  strreplace(sbuff, "}", "\\rbrace~\\!\\!", 0);
  if (mode >= 1)
    strreplace(sbuff, "_", "\\_", 0);
  else
    strreplace(sbuff, "_", "\\underline{\\qquad}", 0);
  if (0)
    strreplace(sbuff, "<", "\\textlangle ", 0);
  if (0)
    strreplace(sbuff, ">", "\\textrangle ", 0);
  if (0)
    strreplace(sbuff, "$", "\\textdollar ", 0);
  strreplace(sbuff, "$", "\\$", 0);
  strreplace(sbuff, "&", "\\&", 0);
  strreplace(sbuff, "%", "\\%", 0);
  strreplace(sbuff, "#", "\\#", 0);
  strreplace(sbuff, "^", "{\\fs{+2}\\^}", 0);
end_of_job:
  return (sbuff);
}


x86 assembly (clang, -O0):
<strdetex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,0x2f0a(%rip)
cmpq   $0x0,-0x8(%rbp)
jne    1150 <strdetex+0x30>
mov    $0x1,%al
test   $0x1,%al
jne    117e <strdetex+0x5e>
jmp    1183 <strdetex+0x63>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116f <strdetex+0x4f>
mov    $0x1,%al
test   $0x1,%al
jne    117e <strdetex+0x5e>
jmp    1183 <strdetex+0x63>
xor    %eax,%eax
test   $0x1,%al
jne    117e <strdetex+0x5e>
jmp    1183 <strdetex+0x63>
jmp    12f4 <strdetex+0x1d4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movb   $0x0,0x2eae(%rip)
cmpq   $0x0,-0x18(%rbp)
je     11b9 <strdetex+0x99>
mov    -0x18(%rbp),%rsi
lea    0x2e98(%rip),%rdi
mov    $0x800,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x3687(%rip)
lea    0x2e80(%rip),%rdi
lea    0xe39(%rip),%rsi
lea    0xe34(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
lea    0x2e62(%rip),%rdi
lea    0xe2d(%rip),%rsi
lea    0xe28(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
lea    0x2e44(%rip),%rdi
lea    0xe59(%rip),%rsi
lea    0xe17(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
cmpl   $0x1,-0xc(%rbp)
jl     1240 <strdetex+0x120>
lea    0x2e1c(%rip),%rdi
lea    0xe04(%rip),%rsi
lea    0xdfc(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
jmp    125e <strdetex+0x13e>
lea    0x2df9(%rip),%rdi
lea    0xde1(%rip),%rsi
lea    0xddc(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
lea    0x2ddb(%rip),%rdi
lea    0xdd9(%rip),%rsi
lea    0xdd1(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
lea    0x2dbd(%rip),%rdi
lea    0xdbe(%rip),%rsi
lea    0xdb6(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
lea    0x2d9f(%rip),%rdi
lea    0xda3(%rip),%rsi
lea    0xd9b(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
lea    0x2d81(%rip),%rdi
lea    0xd88(%rip),%rsi
lea    0xd80(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
lea    0x2d63(%rip),%rdi
lea    0xd6c(%rip),%rsi
lea    0xd67(%rip),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1040 <strreplace@plt>
lea    0x2d45(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdetex>:
push   %rbp
push   %rbx
push   %rax
movb   $0x0,0x2f16(%rip)
test   %rdi,%rdi
je     1253 <strdetex+0x133>
mov    %esi,%ebp
mov    %rdi,%rsi
cmpb   $0x0,(%rdi)
je     1253 <strdetex+0x133>
lea    0x2ef8(%rip),%rbx
mov    %rbx,%rdi
mov    $0x800,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x36e4(%rip)
lea    0xe9d(%rip),%rsi
lea    0xe98(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <strreplace@plt>
lea    0xe95(%rip),%rsi
lea    0xe90(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <strreplace@plt>
lea    0xec5(%rip),%rsi
lea    0xe83(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <strreplace@plt>
test   %ebp,%ebp
lea    0xe7b(%rip),%rax
lea    0xe77(%rip),%rdx
cmovg  %rax,%rdx
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <strreplace@plt>
lea    0xe6d(%rip),%rsi
lea    0xe65(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <strreplace@plt>
lea    0xe56(%rip),%rsi
lea    0xe4e(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <strreplace@plt>
lea    0xe3f(%rip),%rsi
lea    0xe37(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <strreplace@plt>
lea    0xe28(%rip),%rsi
lea    0xe20(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <strreplace@plt>
lea    0xe10(%rip),%rsi
lea    0xe0b(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %eax,%eax
call   1040 <strreplace@plt>
lea    0x2de6(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@strdetex.sbuff = internal global [4096 x i8] zeroinitializer
@.str = [2 x i8] c"\\\00"
@.str.1 = [16 x i8] c"\\backslash~\\!\\!\00"
@.str.2 = [2 x i8] c"{\00"
@.str.3 = [13 x i8] c"\\lbrace~\\!\\!\00"
@.str.4 = [2 x i8] c"}\00"
@.str.5 = [13 x i8] c"\\rbrace~\\!\\!\00"
@.str.6 = [2 x i8] c"_\00"
@.str.7 = [3 x i8] c"\\_\00"
@.str.8 = [19 x i8] c"\\underline{\\qquad}\00"
@.str.9 = [2 x i8] c"$\00"
@.str.10 = [3 x i8] c"\\$\00"
@.str.11 = [2 x i8] c"&\00"
@.str.12 = [3 x i8] c"\\&\00"
@.str.13 = [2 x i8] c"%\00"
@.str.14 = [3 x i8] c"\\%\00"
@.str.15 = [2 x i8] c"#\00"
@.str.16 = [3 x i8] c"\\#\00"
@.str.17 = [2 x i8] c"^\00"
@.str.18 = [12 x i8] c"{\\fs{+2}\\^}\00"
define i8* @strdetex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8 0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %2
br i1 true, label %16, label %17
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
br i1 true, label %16, label %17
15: ; preds = %9
br i1 false, label %16, label %17
16: ; preds = %15, %14, %8
br label %40
17: ; preds = %15, %14, %8
%18 = load i8*, i8** %3
store i8* %18, i8** %5
store i8 0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0)
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = call i32 @strncpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* %22, i32 2048)
store i8 0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 2048)
br label %24
24: ; preds = %21, %17
%25 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 0)
%26 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 0)
%27 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 0)
%28 = load i32, i32* %4
%29 = icmp sge i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 0)
br label %34
32: ; preds = %24
%33 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 0)
br label %34
34: ; preds = %32, %30
%35 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 0)
%36 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 0)
%37 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 0)
%38 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0), i32 0)
%39 = call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0), i32 0)
br label %40
40: ; preds = %34, %16
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0)
}

LLVM IR (-O2):
@strdetex.sbuff = internal global [4096 x i8] zeroinitializer
@.str = [2 x i8] c"\\\00"
@.str.1 = [16 x i8] c"\\backslash~\\!\\!\00"
@.str.2 = [2 x i8] c"{\00"
@.str.3 = [13 x i8] c"\\lbrace~\\!\\!\00"
@.str.4 = [2 x i8] c"}\00"
@.str.5 = [13 x i8] c"\\rbrace~\\!\\!\00"
@.str.6 = [2 x i8] c"_\00"
@.str.7 = [3 x i8] c"\\_\00"
@.str.8 = [19 x i8] c"\\underline{\\qquad}\00"
@.str.9 = [2 x i8] c"$\00"
@.str.10 = [3 x i8] c"\\$\00"
@.str.11 = [2 x i8] c"&\00"
@.str.12 = [3 x i8] c"\\&\00"
@.str.13 = [2 x i8] c"%\00"
@.str.14 = [3 x i8] c"\\%\00"
@.str.15 = [2 x i8] c"#\00"
@.str.16 = [3 x i8] c"\\#\00"
@.str.17 = [2 x i8] c"^\00"
@.str.18 = [12 x i8] c"{\\fs{+2}\\^}\00"
define i8* @strdetex(i8* %0, i32 %1) {
store i8 0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0)
%3 = icmp eq i8* %0, null
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %4
%8 = tail call i32 @strncpy(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* %0, i32 2048)
store i8 0, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 2048)
%9 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 0)
%10 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 0)
%11 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 0)
%12 = icmp sgt i32 %1, 0
%13 = select i1 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0)
%14 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %13, i32 0)
%15 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 0)
%16 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0), i32 0)
%17 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0), i32 0)
%18 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0), i32 0)
%19 = tail call i32 (i8*, i8*, i8*, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.18, i64 0, i64 0), i32 0)
br label %20
20: ; preds = %2, %4, %7
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @strdetex.sbuff, i64 0, i64 0)
}