#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*/ PopSource();
int /*<<< orphan*/ PushSource(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ diagnostics(int, char *, char *);
int /*<<< orphan*/ free(char *);
char *getBraceParam();
char *strdup_nobadchars(char *);
int /*<<< orphan*/ strlen(char *);
char *strstr(char const *, char *);
char *ExtractLabelTag(const char *text) {
  char *s, *label_with_spaces, *label;
  s = strstr(text, "\\label{");
  if (!s)
    s = strstr(text, "\\label ");
  if (!s)
    return NULL;
  s += strlen("\\label");
  PushSource(NULL, s);
  label_with_spaces = getBraceParam();
  PopSource();
  label = strdup_nobadchars(label_with_spaces);
  free(label_with_spaces);
  diagnostics(4, "LabelTag = <%s>", (label) ? label : "missing");
  return label;
}


x86 assembly (clang, -O0):
<ExtractLabelTag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bf <ExtractLabelTag+0x3f>
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d7 <ExtractLabelTag+0x57>
movq   $0x0,-0x8(%rbp)
jmp    126d <ExtractLabelTag+0xed>
lea    0xe32(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <PushSource@plt>
mov    $0x0,%al
call   1060 <getBraceParam@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1090 <PopSource@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strdup_nobadchars@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
je     1240 <ExtractLabelTag+0xc0>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1250 <ExtractLabelTag+0xd0>
lea    0xde0(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1250 <ExtractLabelTag+0xd0>
mov    -0x30(%rbp),%rdx
mov    $0x4,%edi
lea    0xdb7(%rip),%rsi
call   1080 <diagnostics@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExtractLabelTag>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe72(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b2 <ExtractLabelTag+0x32>
lea    0xe66(%rip),%rsi
mov    %r14,%rdi
call   10a0 <strstr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1219 <ExtractLabelTag+0x99>
lea    0xe57(%rip),%rdi
call   1050 <strlen@plt>
movslq %eax,%rsi
add    %rbx,%rsi
xor    %edi,%edi
call   1070 <PushSource@plt>
xor    %eax,%eax
call   1060 <getBraceParam@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1090 <PopSource@plt>
mov    %r14,%rdi
call   1040 <strdup_nobadchars@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
test   %rbx,%rbx
lea    0xe2e(%rip),%rdx
cmovne %rbx,%rdx
lea    0xe13(%rip),%rsi
mov    $0x4,%edi
call   1080 <diagnostics@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %ebx,%ebx
jmp    120e <ExtractLabelTag+0x8e>

LLVM IR (-O0):
@.str = [8 x i8] c"\\label{\00"
@.str.1 = [8 x i8] c"\\label \00"
@.str.2 = [7 x i8] c"\\label\00"
@.str.3 = [16 x i8] c"LabelTag = <%s>\00"
@.str.4 = [8 x i8] c"missing\00"
define i8* @ExtractLabelTag(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strstr(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %4
br label %14
14: ; preds = %11, %1
%15 = load i8*, i8** %4
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i8* null, i8** %2
br label %40
18: ; preds = %14
%19 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%20 = load i8*, i8** %4
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = call i32 @PushSource(i32* null, i8* %23)
%25 = call i8* (...) @getBraceParam()
store i8* %25, i8** %5
%26 = call i32 (...) @PopSource()
%27 = load i8*, i8** %5
%28 = call i8* @strdup_nobadchars(i8* %27)
store i8* %28, i8** %6
%29 = load i8*, i8** %5
%30 = call i32 @free(i8* %29)
%31 = load i8*, i8** %6
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %18
%34 = load i8*, i8** %6
br label %36
35: ; preds = %18
br label %36
36: ; preds = %35, %33
%37 = phi i8* [ %34, %33 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %35 ]
%38 = call i32 @diagnostics(i32 4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %6
store i8* %39, i8** %2
br label %40
40: ; preds = %36, %17
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@.str = [8 x i8] c"\\label{\00"
@.str.1 = [8 x i8] c"\\label \00"
@.str.2 = [7 x i8] c"\\label\00"
@.str.3 = [16 x i8] c"LabelTag = <%s>\00"
@.str.4 = [8 x i8] c"missing\00"
define i8* @ExtractLabelTag(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %1, %4
%8 = phi i8* [ %5, %4 ], [ %2, %1 ]
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = tail call i32 @PushSource(i32* null, i8* %11)
%13 = tail call i8* (...) @getBraceParam()
%14 = tail call i32 (...) @PopSource()
%15 = tail call i8* @strdup_nobadchars(i8* %13)
%16 = tail call i32 @free(i8* %13)
%17 = icmp eq i8* %15, null
%18 = select i1 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %15
%19 = tail call i32 @diagnostics(i32 4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %4, %7
%21 = phi i8* [ %15, %7 ], [ null, %4 ]
ret i8* %21
}