#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ RB_XMLDB_Generate_Char(int /*<<< orphan*/ *, char);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int strlen(char *);
scalar_t__ utf8_isalnum(unsigned char);
void RB_XMLDB_Generate_Label(FILE *dest_doc, char *name) {
  int i;
  int l = strlen(name);
  unsigned char c;
  fprintf(dest_doc, "<anchor id=\"");
  for (i = 0; i < l; ++i) {
    c = name[i];
    if (utf8_isalnum(c)) {
      RB_XMLDB_Generate_Char(dest_doc, c);
    } else {
      char buf[4];
      sprintf(buf, "%02x", c);
      RB_XMLDB_Generate_Char(dest_doc, buf[0]);
      RB_XMLDB_Generate_Char(dest_doc, buf[1]);
    }
  }
  fprintf(dest_doc, "\"/>\n");
}


x86 assembly (clang, -O0):
<RB_XMLDB_Generate_Label>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1203 <RB_XMLDB_Generate_Label+0xb3>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%edi
call   1060 <utf8_isalnum@plt>
cmp    $0x0,%rax
je     11c2 <RB_XMLDB_Generate_Label+0x72>
mov    -0x8(%rbp),%rdi
movsbl -0x19(%rbp),%esi
call   1050 <RB_XMLDB_Generate_Char@plt>
jmp    11f0 <RB_XMLDB_Generate_Label+0xa0>
lea    -0x1d(%rbp),%rdi
lea    0xe40(%rip),%rsi
movzbl -0x19(%rbp),%edx
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
movsbl -0x1d(%rbp),%esi
call   1050 <RB_XMLDB_Generate_Char@plt>
mov    -0x8(%rbp),%rdi
movsbl -0x1c(%rbp),%esi
call   1050 <RB_XMLDB_Generate_Char@plt>
jmp    11f5 <RB_XMLDB_Generate_Label+0xa5>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1183 <RB_XMLDB_Generate_Label+0x33>
mov    -0x8(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RB_XMLDB_Generate_Label>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
lea    0xe8e(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
test   %ebp,%ebp
jle    11e1 <RB_XMLDB_Generate_Label+0x91>
mov    %ebp,%r13d
xor    %r15d,%r15d
jmp    11c6 <RB_XMLDB_Generate_Label+0x76>
lea    0x4(%rsp),%rdi
lea    0xe71(%rip),%rsi
mov    %ebp,%edx
call   1060 <sprintf@plt>
movsbl 0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <RB_XMLDB_Generate_Char@plt>
movsbl 0x5(%rsp),%esi
mov    %rbx,%rdi
call   1040 <RB_XMLDB_Generate_Char@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     11e1 <RB_XMLDB_Generate_Label+0x91>
movzbl (%r14,%r15,1),%r12d
movzbl %r12b,%ebp
mov    %ebp,%edi
call   1050 <utf8_isalnum@plt>
test   %rax,%rax
je     1190 <RB_XMLDB_Generate_Label+0x40>
movsbl %r12b,%esi
jmp    11b5 <RB_XMLDB_Generate_Label+0x65>
lea    0xe2a(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fwrite@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"<anchor id=\22\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [5 x i8] c"\22/>\0A\00"
define void @RB_XMLDB_Generate_Label(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca [4 x i8]
store i32* %0, i32** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i32*, i32** %3
%12 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %13
13: ; preds = %43, %2
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %46
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
store i8 %22, i8* %7
%23 = load i8, i8* %7
%24 = call i64 @utf8_isalnum(i8 zeroext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = load i32*, i32** %3
%28 = load i8, i8* %7
%29 = call i32 @RB_XMLDB_Generate_Char(i32* %27, i8 signext %28)
br label %42
30: ; preds = %17
%31 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%32 = load i8, i8* %7
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %32)
%34 = load i32*, i32** %3
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%36 = load i8, i8* %35
%37 = call i32 @RB_XMLDB_Generate_Char(i32* %34, i8 signext %36)
%38 = load i32*, i32** %3
%39 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
%40 = load i8, i8* %39
%41 = call i32 @RB_XMLDB_Generate_Char(i32* %38, i8 signext %40)
br label %42
42: ; preds = %30, %26
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %13
46: ; preds = %13
%47 = load i32*, i32** %3
%48 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"<anchor id=\22\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [5 x i8] c"\22/>\0A\00"
define void @RB_XMLDB_Generate_Label(i32* %0, i8* %1) {
%3 = alloca [4 x i8]
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 12, i64 1, i32* %0)
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %28
7: ; preds = %2
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%10 = zext i32 %4 to i64
br label %11
11: ; preds = %7, %25
%12 = phi i64 [ 0, %7 ], [ %26, %25 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = tail call i64 @utf8_isalnum(i8 zeroext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = tail call i32 @RB_XMLDB_Generate_Char(i32* %0, i8 signext %14)
br label %25
19: ; preds = %11
%20 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %14)
%21 = load i8, i8* %8
%22 = tail call i32 @RB_XMLDB_Generate_Char(i32* %0, i8 signext %21)
%23 = load i8, i8* %9
%24 = tail call i32 @RB_XMLDB_Generate_Char(i32* %0, i8 signext %23)
br label %25
25: ; preds = %17, %19
%26 = add nuw nsw i64 %12, 1
%27 = icmp eq i64 %26, %10
br i1 %27, label %28, label %11
28: ; preds = %25, %2
%29 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4, i64 1, i32* %0)
ret void
}