#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char const, int /*<<< orphan*/ *);
int strlen(char const *);
void rhs_handler(const char *template, FILE *out, const char *nt,
                 const char *sym_name, int prod_num, int seq_num) {
  int i;
  for (i = 0; i < strlen(template); i++) {
    switch (template[i]) {
    case 'n':
      fprintf(out, "%s", nt);
      break;
    case 'r':
      fprintf(out, "%s", sym_name);
      break;
    case 'p':
      fprintf(out, "%d", prod_num);
      break;
    case 's':
      fprintf(out, "%d", seq_num);
      break;
    default:
      fputc(template[i], out);
      break;
    }
  }
  fputc('\n', out);
}


x86 assembly (clang, -O0):
<rhs_handler>:
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    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jge    1239 <rhs_handler+0x109>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffff92,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x5,%eax
ja     120f <rhs_handler+0xdf>
mov    -0x38(%rbp),%rax
lea    0xe64(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1226 <rhs_handler+0xf6>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1226 <rhs_handler+0xf6>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1226 <rhs_handler+0xf6>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1226 <rhs_handler+0xf6>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    122b <rhs_handler+0xfb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1157 <rhs_handler+0x27>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rhs_handler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8d,0x8(%rsp)
mov    %rcx,0x10(%rsp)
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1030 <strlen@plt>
test   %eax,%eax
jle    1203 <rhs_handler+0xc3>
lea    0xe86(%rip),%r15
lea    0xe97(%rip),%r14
xor    %r12d,%r12d
jmp    11b3 <rhs_handler+0x73>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%r12
jge    1203 <rhs_handler+0xc3>
movsbl 0x0(%rbp,%r12,1),%eax
lea    -0x6e(%rax),%ecx
cmp    $0x5,%ecx
ja     1190 <rhs_handler+0x50>
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
mov    %r13,%rdi
jmp    11e5 <rhs_handler+0xa5>
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    0x8(%rsp),%edx
jmp    11fa <rhs_handler+0xba>
nopl   0x0(%rax)
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
jmp    11a0 <rhs_handler+0x60>
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11a0 <rhs_handler+0x60>
mov    $0xa,%edi
mov    %rbx,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fputc@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%d\00"
define void @rhs_handler(i8* %0, i32* %1, i8* %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i32* %1, i32** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 0, i32* %13
br label %14
14: ; preds = %51, %6
%15 = load i32, i32* %13
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %54
19: ; preds = %14
%20 = load i8*, i8** %7
%21 = load i32, i32* %13
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
switch i32 %25, label %42 [
i32 110, label %26
i32 114, label %30
i32 112, label %34
i32 115, label %38
]
26: ; preds = %19
%27 = load i32*, i32** %8
%28 = load i8*, i8** %9
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %50
30: ; preds = %19
%31 = load i32*, i32** %8
%32 = load i8*, i8** %10
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %50
34: ; preds = %19
%35 = load i32*, i32** %8
%36 = load i32, i32* %11
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %50
38: ; preds = %19
%39 = load i32*, i32** %8
%40 = load i32, i32* %12
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %50
42: ; preds = %19
%43 = load i8*, i8** %7
%44 = load i32, i32* %13
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = load i32*, i32** %8
%49 = call i32 @fputc(i8 signext %47, i32* %48)
br label %50
50: ; preds = %42, %38, %34, %30, %26
br label %51
51: ; preds = %50
%52 = load i32, i32* %13
%53 = add nsw i32 %52, 1
store i32 %53, i32* %13
br label %14
54: ; preds = %14
%55 = load i32*, i32** %8
%56 = call i32 @fputc(i8 signext 10, i32* %55)
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
define void @rhs_handler(i8* %0, i32* nocapture %1, i8* nocapture %2, i8* nocapture %3, i32 %4, i32 %5) {
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %29
9: ; preds = %6, %24
%10 = phi i64 [ %25, %24 ], [ 0, %6 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %22 [
i32 110, label %14
i32 114, label %16
i32 112, label %18
i32 115, label %20
]
14: ; preds = %9
%15 = tail call i32 @fputs(i8* %2, i32* %1)
br label %24
16: ; preds = %9
%17 = tail call i32 @fputs(i8* %3, i32* %1)
br label %24
18: ; preds = %9
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %24
20: ; preds = %9
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %5)
br label %24
22: ; preds = %9
%23 = tail call i32 @fputc(i8 signext %12, i32* %1)
br label %24
24: ; preds = %14, %16, %18, %20, %22
%25 = add nuw nsw i64 %10, 1
%26 = tail call i32 @strlen(i8* %0)
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %9, label %29
29: ; preds = %24, %6
%30 = tail call i32 @fputc(i8 signext 10, i32* %1)
ret void
}