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


x86 assembly (clang, -O0):
<lhs_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11f7 <lhs_handler+0xc7>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
sub    $0x6e,%eax
je     1198 <lhs_handler+0x68>
jmp    1187 <lhs_handler+0x57>
mov    -0x28(%rbp),%eax
sub    $0x70,%eax
je     11b3 <lhs_handler+0x83>
jmp    11cd <lhs_handler+0x9d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11e4 <lhs_handler+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11e4 <lhs_handler+0xb4>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    11e9 <lhs_handler+0xb9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114e <lhs_handler+0x1e>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lhs_handler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbp
call   1030 <strlen@plt>
test   %eax,%eax
jle    11c2 <lhs_handler+0x82>
lea    0xe99(%rip),%r12
xor    %ebx,%ebx
jmp    118b <lhs_handler+0x4b>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11c2 <lhs_handler+0x82>
movsbl 0x0(%rbp,%rbx,1),%edi
cmp    $0x70,%edi
je     11b0 <lhs_handler+0x70>
cmp    $0x6e,%edi
jne    1170 <lhs_handler+0x30>
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <fputs@plt>
jmp    1178 <lhs_handler+0x38>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1178 <lhs_handler+0x38>
mov    $0xa,%edi
mov    %r13,%rsi
add    $0x8,%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 @lhs_handler(i8* %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %39, %4
%11 = load i32, i32* %9
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %42
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %30 [
i32 110, label %22
i32 112, label %26
]
22: ; preds = %15
%23 = load i32*, i32** %6
%24 = load i8*, i8** %7
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %38
26: ; preds = %15
%27 = load i32*, i32** %6
%28 = load i32, i32* %8
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %38
30: ; preds = %15
%31 = load i8*, i8** %5
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = load i32*, i32** %6
%37 = call i32 @fputc(i8 signext %35, i32* %36)
br label %38
38: ; preds = %30, %26, %22
br label %39
39: ; preds = %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %10
42: ; preds = %10
%43 = load i32*, i32** %6
%44 = call i32 @fputc(i8 signext 10, i32* %43)
ret void
}

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