#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 */
scalar_t__ ExistsBookmark(char *);
int /*<<< orphan*/ RecordBookmark(char *);
int /*<<< orphan*/ changeTexMode(int);
int /*<<< orphan*/ diagnostics(int, char *, char *, ...);
scalar_t__ fields_use_REF();
int /*<<< orphan*/ fprintRTF(char *, char *);
int getTexMode();
int /*<<< orphan*/ safe_free(char *);
char *strdup_nobadchars(char *);
void InsertBookmark(char *name, char *text) {
  char *signet;
  if (!name) {
    if (getTexMode() == 6)
      changeTexMode(2);
    fprintRTF("%s", text);
    return;
  }
  signet = strdup_nobadchars(name);
  if (ExistsBookmark(signet)) {
    diagnostics(4, "bookmark %s already exists", signet);
  } else {
    diagnostics(4, "bookmark %s being inserted around <%s>", signet, text);
    RecordBookmark(signet);
    if (fields_use_REF())
      fprintRTF("{\\*\\bkmkstart BM%s}", signet);
    fprintRTF("%s", text);
    if (fields_use_REF())
      fprintRTF("{\\*\\bkmkend BM%s}", signet);
  }
  safe_free(signet);
}


x86 assembly (clang, -O0):
<InsertBookmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11da <InsertBookmark+0x4a>
mov    $0x0,%al
call   1050 <getTexMode@plt>
cmp    $0x6,%eax
jne    11c5 <InsertBookmark+0x35>
mov    $0x2,%edi
call   1030 <changeTexMode@plt>
mov    -0x10(%rbp),%rsi
lea    0xe30(%rip),%rdi
call   10a0 <fprintRTF@plt>
jmp    129a <InsertBookmark+0x10a>
mov    -0x8(%rbp),%rdi
call   1040 <strdup_nobadchars@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10b0 <ExistsBookmark@plt>
cmp    $0x0,%rax
je     1216 <InsertBookmark+0x86>
mov    -0x18(%rbp),%rdx
mov    $0x4,%edi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1060 <diagnostics@plt>
jmp    1291 <InsertBookmark+0x101>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x4,%edi
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1060 <diagnostics@plt>
mov    -0x18(%rbp),%rdi
call   1070 <RecordBookmark@plt>
mov    $0x0,%al
call   1080 <fields_use_REF@plt>
cmp    $0x0,%rax
je     125b <InsertBookmark+0xcb>
mov    -0x18(%rbp),%rsi
lea    0xdef(%rip),%rdi
call   10a0 <fprintRTF@plt>
mov    -0x10(%rbp),%rsi
lea    0xd9a(%rip),%rdi
call   10a0 <fprintRTF@plt>
mov    $0x0,%al
call   1080 <fields_use_REF@plt>
cmp    $0x0,%rax
je     128c <InsertBookmark+0xfc>
mov    -0x18(%rbp),%rsi
lea    0xdd2(%rip),%rdi
call   10a0 <fprintRTF@plt>
jmp    1291 <InsertBookmark+0x101>
mov    -0x18(%rbp),%rdi
call   1090 <safe_free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InsertBookmark>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     11cc <InsertBookmark+0x3c>
call   1040 <strdup_nobadchars@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <ExistsBookmark@plt>
test   %rax,%rax
je     11f8 <InsertBookmark+0x68>
lea    0xe4b(%rip),%rsi
mov    $0x4,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <diagnostics@plt>
jmp    125e <InsertBookmark+0xce>
xor    %eax,%eax
call   1050 <getTexMode@plt>
cmp    $0x6,%eax
jne    11e2 <InsertBookmark+0x52>
mov    $0x2,%edi
call   1030 <changeTexMode@plt>
lea    0xe17(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    10a0 <fprintRTF@plt>
lea    0xe1f(%rip),%rsi
mov    $0x4,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <diagnostics@plt>
mov    %rbx,%rdi
call   1070 <RecordBookmark@plt>
xor    %eax,%eax
call   1080 <fields_use_REF@plt>
test   %rax,%rax
je     1234 <InsertBookmark+0xa4>
lea    0xe19(%rip),%rdi
mov    %rbx,%rsi
call   10a0 <fprintRTF@plt>
lea    0xdc5(%rip),%rdi
mov    %r14,%rsi
call   10a0 <fprintRTF@plt>
xor    %eax,%eax
call   1080 <fields_use_REF@plt>
test   %rax,%rax
je     125e <InsertBookmark+0xce>
lea    0xe03(%rip),%rdi
mov    %rbx,%rsi
call   10a0 <fprintRTF@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1090 <safe_free@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [27 x i8] c"bookmark %s already exists\00"
@.str.2 = [39 x i8] c"bookmark %s being inserted around <%s>\00"
@.str.3 = [20 x i8] c"{\\*\\bkmkstart BM%s}\00"
@.str.4 = [18 x i8] c"{\\*\\bkmkend BM%s}\00"
define void @InsertBookmark(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %16, label %8
8: ; preds = %2
%9 = call i32 (...) @getTexMode()
%10 = icmp eq i32 %9, 6
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 @changeTexMode(i32 2)
br label %13
13: ; preds = %11, %8
%14 = load i8*, i8** %4
%15 = call i32 @fprintRTF(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %48
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i8* @strdup_nobadchars(i8* %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = call i64 @ExistsBookmark(i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %5
%24 = call i32 (i32, i8*, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %45
25: ; preds = %16
%26 = load i8*, i8** %5
%27 = load i8*, i8** %4
%28 = call i32 (i32, i8*, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %26, i8* %27)
%29 = load i8*, i8** %5
%30 = call i32 @RecordBookmark(i8* %29)
%31 = call i64 (...) @fields_use_REF()
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load i8*, i8** %5
%35 = call i32 @fprintRTF(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %33, %25
%37 = load i8*, i8** %4
%38 = call i32 @fprintRTF(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = call i64 (...) @fields_use_REF()
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i8*, i8** %5
%43 = call i32 @fprintRTF(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %41, %36
br label %45
45: ; preds = %44, %22
%46 = load i8*, i8** %5
%47 = call i32 @safe_free(i8* %46)
br label %48
48: ; preds = %45, %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [27 x i8] c"bookmark %s already exists\00"
@.str.2 = [39 x i8] c"bookmark %s being inserted around <%s>\00"
@.str.3 = [20 x i8] c"{\\*\\bkmkstart BM%s}\00"
@.str.4 = [18 x i8] c"{\\*\\bkmkend BM%s}\00"
define void @InsertBookmark(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = tail call i32 (...) @getTexMode()
%6 = icmp eq i32 %5, 6
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @changeTexMode(i32 2)
br label %9
9: ; preds = %7, %4
%10 = tail call i32 @fprintRTF(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %32
11: ; preds = %2
%12 = tail call i8* @strdup_nobadchars(i8* %0)
%13 = tail call i64 @ExistsBookmark(i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 (i32, i8*, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %30
17: ; preds = %11
%18 = tail call i32 (i32, i8*, i8*, ...) @diagnostics(i32 4, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %12, i8* %1)
%19 = tail call i32 @RecordBookmark(i8* %12)
%20 = tail call i64 (...) @fields_use_REF()
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = tail call i32 @fprintRTF(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %12)
br label %24
24: ; preds = %22, %17
%25 = tail call i32 @fprintRTF(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%26 = tail call i64 (...) @fields_use_REF()
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = tail call i32 @fprintRTF(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %12)
br label %30
30: ; preds = %24, %28, %15
%31 = tail call i32 @safe_free(i8* %12)
br label %32
32: ; preds = %30, %9
ret void
}