#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, ...);
int /*<<< orphan*/ putc(unsigned char, int /*<<< orphan*/ *);
void emit_encoding(FILE *out1, FILE *out2, const char *tag,
                   const char *const *names, size_t n, const char *c_name) {
  static unsigned int counter = 0;
  fprintf(out2,
          "  (int)(long)&((struct stringpool2_t *)0)->stringpool_%s_%u,\n", tag,
          counter);
  for (; n > 0; names++, n--, counter++) {
    fprintf(out1, "  S(%s_%u, \"", tag, counter);
    {
      const char *s = *names;
      for (; *s; s++) {
        unsigned char c = *(unsigned char *)s;
        if (c >= 0x80)
          exit(1);
        if (c >= 'a' && c <= 'z')
          c -= 'a' - 'A';
        putc(c, out1);
      }
    }
    fprintf(out1, "\", ei_%s )\n", c_name);
  }
}


x86 assembly (clang, -O0):
<emit_encoding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2ede(%rip),%ecx
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpq   $0x0,-0x28(%rbp)
jbe    1253 <emit_encoding+0x123>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    0x2eb7(%rip),%ecx
lea    0xeb2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     1211 <emit_encoding+0xe1>
mov    -0x38(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x39(%rbp)
movzbl -0x39(%rbp),%eax
cmp    $0x80,%eax
jl     11cd <emit_encoding+0x9d>
mov    $0x1,%edi
call   1050 <exit@plt>
movzbl -0x39(%rbp),%eax
cmp    $0x61,%eax
jl     11f1 <emit_encoding+0xc1>
movzbl -0x39(%rbp),%eax
cmp    $0x7a,%eax
jg     11f1 <emit_encoding+0xc1>
movzbl -0x39(%rbp),%eax
sub    $0x20,%eax
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
mov    -0x8(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    119e <emit_encoding+0x6e>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    0x2df7(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2dee(%rip)
jmp    116c <emit_encoding+0x3c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_encoding>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r13
mov    %rdx,%r12
mov    %rsi,%rax
mov    %rdi,%rbx
mov    0x2ee9(%rip),%ecx
lea    0xea6(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r15,%r15
je     11ff <emit_encoding+0xcf>
mov    0x2ec9(%rip),%ecx
jmp    11ad <emit_encoding+0x7d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
lea    0xec1(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x8,%r13
mov    0x2e9e(%rip),%ecx
add    $0x1,%ecx
mov    %ecx,0x2e95(%rip)
add    $0xffffffffffffffff,%r15
je     11ff <emit_encoding+0xcf>
mov    %rbx,%rdi
lea    0xe87(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%r13),%rbp
mov    0x0(%rbp),%al
test   %al,%al
je     1180 <emit_encoding+0x50>
add    $0x1,%rbp
test   %al,%al
js     120e <emit_encoding+0xde>
lea    -0x61(%rax),%ecx
lea    -0x20(%rax),%edx
cmp    $0x1a,%cl
movzbl %al,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
movzbl %cl,%edi
mov    %rbx,%rsi
call   1030 <putc@plt>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    11d0 <emit_encoding+0xa0>
jmp    1180 <emit_encoding+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@emit_encoding.counter = internal global i32 0
@.str = [62 x i8] c" (int)(long)&((struct stringpool2_t *)0)->stringpool_%s_%u,\0A\00"
@.str.1 = [13 x i8] c" S(%s_%u, \22\00"
@.str.2 = [12 x i8] c"\22, ei_%s )\0A\00"
define void @emit_encoding(i32* %0, i32* %1, i8* %2, i8** %3, i64 %4, i8* %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8**
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8
store i32* %0, i32** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i8** %3, i8*** %10
store i64 %4, i64* %11
store i8* %5, i8** %12
%15 = load i32*, i32** %8
%16 = load i8*, i8** %9
%17 = load i32, i32* @emit_encoding.counter
%18 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17)
br label %19
19: ; preds = %65, %6
%20 = load i64, i64* %11
%21 = icmp ugt i64 %20, 0
br i1 %21, label %22, label %72
22: ; preds = %19
%23 = load i32*, i32** %7
%24 = load i8*, i8** %9
%25 = load i32, i32* @emit_encoding.counter
%26 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %24, i32 %25)
%27 = load i8**, i8*** %10
%28 = load i8*, i8** %27
store i8* %28, i8** %13
br label %29
29: ; preds = %58, %22
%30 = load i8*, i8** %13
%31 = load i8, i8* %30
%32 = icmp ne i8 %31, 0
br i1 %32, label %33, label %61
33: ; preds = %29
%34 = load i8*, i8** %13
%35 = load i8, i8* %34
store i8 %35, i8* %14
%36 = load i8, i8* %14
%37 = zext i8 %36 to i32
%38 = icmp sge i32 %37, 128
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %33
%42 = load i8, i8* %14
%43 = zext i8 %42 to i32
%44 = icmp sge i32 %43, 97
br i1 %44, label %45, label %54
45: ; preds = %41
%46 = load i8, i8* %14
%47 = zext i8 %46 to i32
%48 = icmp sle i32 %47, 122
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = load i8, i8* %14
%51 = zext i8 %50 to i32
%52 = sub nsw i32 %51, 32
%53 = trunc i32 %52 to i8
store i8 %53, i8* %14
br label %54
54: ; preds = %49, %45, %41
%55 = load i8, i8* %14
%56 = load i32*, i32** %7
%57 = call i32 @putc(i8 zeroext %55, i32* %56)
br label %58
58: ; preds = %54
%59 = load i8*, i8** %13
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %13
br label %29
61: ; preds = %29
%62 = load i32*, i32** %7
%63 = load i8*, i8** %12
%64 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %62, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %61
%66 = load i8**, i8*** %10
%67 = getelementptr inbounds i8*, i8** %66, i32 1
store i8** %67, i8*** %10
%68 = load i64, i64* %11
%69 = add i64 %68, -1
store i64 %69, i64* %11
%70 = load i32, i32* @emit_encoding.counter
%71 = add i32 %70, 1
store i32 %71, i32* @emit_encoding.counter
br label %19
72: ; preds = %19
ret void
}

LLVM IR (-O2):
@emit_encoding.counter = internal unnamed_addr global i32 0
@.str = [62 x i8] c" (int)(long)&((struct stringpool2_t *)0)->stringpool_%s_%u,\0A\00"
@.str.1 = [13 x i8] c" S(%s_%u, \22\00"
@.str.2 = [12 x i8] c"\22, ei_%s )\0A\00"
define void @emit_encoding(i32* nocapture %0, i32* nocapture %1, i8* %2, i8** nocapture %3, i64 %4, i8* %5) {
%7 = load i32, i32* @emit_encoding.counter
%8 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %7)
%9 = icmp eq i64 %4, 0
br i1 %9, label %42, label %10
10: ; preds = %6
%11 = load i32, i32* @emit_encoding.counter
br label %12
12: ; preds = %10, %35
%13 = phi i32 [ %40, %35 ], [ %11, %10 ]
%14 = phi i8** [ %37, %35 ], [ %3, %10 ]
%15 = phi i64 [ %38, %35 ], [ %4, %10 ]
%16 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %13)
%17 = load i8*, i8** %14
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %35, label %20
20: ; preds = %12, %26
%21 = phi i8 [ %33, %26 ], [ %18, %12 ]
%22 = phi i8* [ %32, %26 ], [ %17, %12 ]
%23 = icmp slt i8 %21, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = add nsw i8 %21, -97
%28 = icmp ult i8 %27, 26
%29 = add nsw i8 %21, -32
%30 = select i1 %28, i8 %29, i8 %21
%31 = tail call i32 @putc(i8 zeroext %30, i32* %0)
%32 = getelementptr inbounds i8, i8* %22, i64 1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %35, label %20
35: ; preds = %26, %12
%36 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%37 = getelementptr inbounds i8*, i8** %14, i64 1
%38 = add i64 %15, -1
%39 = load i32, i32* @emit_encoding.counter
%40 = add i32 %39, 1
store i32 %40, i32* @emit_encoding.counter
%41 = icmp eq i64 %38, 0
br i1 %41, label %42, label %12
42: ; preds = %35, %6
ret void
}