#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*/ exit(int);
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ putc(unsigned char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void emit_encoding(const char *tag, const char *const *names, size_t n,
                   const char *c_name) {
  static unsigned int counter = 0;
  for (; n > 0; names++, n--, counter++) {
    printf("  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, stdout);
      }
    }
    printf("\", ei_%s )\n", c_name);
  }
}


x86 assembly (clang, -O0):
<emit_encoding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    122c <emit_encoding+0xfc>
mov    -0x8(%rbp),%rsi
mov    0x2edf(%rip),%edx
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ee <emit_encoding+0xbe>
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
cmp    $0x80,%eax
jl     11a5 <emit_encoding+0x75>
mov    $0x1,%edi
call   1050 <exit@plt>
movzbl -0x29(%rbp),%eax
cmp    $0x61,%eax
jl     11c9 <emit_encoding+0x99>
movzbl -0x29(%rbp),%eax
cmp    $0x7a,%eax
jg     11c9 <emit_encoding+0x99>
movzbl -0x29(%rbp),%eax
sub    $0x20,%eax
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%esi
movzbl %al,%edi
call   1040 <putc@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1176 <emit_encoding+0x46>
mov    -0x20(%rbp),%rsi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    0x2e1e(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e15(%rip)
jmp    1148 <emit_encoding+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_encoding>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     11e0 <emit_encoding+0xb0>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
mov    0x2ee6(%rip),%edx
mov    0x2e83(%rip),%r13
jmp    118a <emit_encoding+0x5a>
nop
lea    0xea6(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x8,%rbx
mov    0x2ec1(%rip),%edx
add    $0x1,%edx
mov    %edx,0x2eb8(%rip)
add    $0xffffffffffffffff,%r15
je     11e0 <emit_encoding+0xb0>
lea    0xe6f(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%rbp
mov    0x0(%rbp),%al
test   %al,%al
je     1160 <emit_encoding+0x30>
add    $0x1,%rbp
nopl   0x0(%rax)
test   %al,%al
js     11ef <emit_encoding+0xbf>
lea    -0x61(%rax),%ecx
lea    -0x20(%rax),%edx
cmp    $0x1a,%cl
movzbl %al,%eax
movzbl %dl,%ecx
cmovae %eax,%ecx
mov    0x0(%r13),%esi
movzbl %cl,%edi
call   1040 <putc@plt>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    11b0 <emit_encoding+0x80>
jmp    1160 <emit_encoding+0x30>
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 = [13 x i8] c" S(%s_%u, \22\00"
@stdout = global i32 0
@.str.1 = [12 x i8] c"\22, ei_%s )\0A\00"
define void @emit_encoding(i8* %0, i8** %1, i64 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
br label %11
11: ; preds = %55, %4
%12 = load i64, i64* %7
%13 = icmp ugt i64 %12, 0
br i1 %13, label %14, label %62
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = load i32, i32* @emit_encoding.counter
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
%18 = load i8**, i8*** %6
%19 = load i8*, i8** %18
store i8* %19, i8** %9
br label %20
20: ; preds = %49, %14
%21 = load i8*, i8** %9
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %52
24: ; preds = %20
%25 = load i8*, i8** %9
%26 = load i8, i8* %25
store i8 %26, i8* %10
%27 = load i8, i8* %10
%28 = zext i8 %27 to i32
%29 = icmp sge i32 %28, 128
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %24
%33 = load i8, i8* %10
%34 = zext i8 %33 to i32
%35 = icmp sge i32 %34, 97
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i8, i8* %10
%38 = zext i8 %37 to i32
%39 = icmp sle i32 %38, 122
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i8, i8* %10
%42 = zext i8 %41 to i32
%43 = sub nsw i32 %42, 32
%44 = trunc i32 %43 to i8
store i8 %44, i8* %10
br label %45
45: ; preds = %40, %36, %32
%46 = load i8, i8* %10
%47 = load i32, i32* @stdout
%48 = call i32 @putc(i8 zeroext %46, i32 %47)
br label %49
49: ; preds = %45
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %9
br label %20
52: ; preds = %20
%53 = load i8*, i8** %8
%54 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52
%56 = load i8**, i8*** %6
%57 = getelementptr inbounds i8*, i8** %56, i32 1
store i8** %57, i8*** %6
%58 = load i64, i64* %7
%59 = add i64 %58, -1
store i64 %59, i64* %7
%60 = load i32, i32* @emit_encoding.counter
%61 = add i32 %60, 1
store i32 %61, i32* @emit_encoding.counter
br label %11
62: ; preds = %11
ret void
}

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