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


x86 assembly (clang, -O0):
<non_term_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11be <non_term_handler+0x8e>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
sub    $0x6e,%al
jne    1194 <non_term_handler+0x64>
jmp    117b <non_term_handler+0x4b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11ab <non_term_handler+0x7b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    11b0 <non_term_handler+0x80>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <non_term_handler+0x27>
mov    -0x10(%rbp),%rsi
mov    $0xa,%edi
call   1040 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<non_term_handler>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <strlen@plt>
test   %eax,%eax
jle    118a <non_term_handler+0x5a>
mov    %eax,%r13d
xor    %ebx,%ebx
jmp    1174 <non_term_handler+0x44>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     118a <non_term_handler+0x5a>
movzbl (%r12,%rbx,1),%eax
cmp    $0x6e,%al
jne    1160 <non_term_handler+0x30>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <fputs@plt>
jmp    116b <non_term_handler+0x3b>
mov    $0xa,%edi
mov    %r15,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <fputc@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @non_term_handler(i8* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
store i32 0, i32* %7
br label %11
11: ; preds = %35, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i32, i32* %7
%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 %26 [
i32 110, label %22
]
22: ; preds = %15
%23 = load i32*, i32** %5
%24 = load i8*, i8** %6
%25 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %34
26: ; preds = %15
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = load i32*, i32** %5
%33 = call i32 @fputc(i8 signext %31, i32* %32)
br label %34
34: ; preds = %26, %22
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %11
38: ; preds = %11
%39 = load i32*, i32** %5
%40 = call i32 @fputc(i8 signext 10, i32* %39)
ret void
}

LLVM IR (-O2):
define void @non_term_handler(i8* %0, i32* nocapture %1, i8* nocapture %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %20
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %17
%9 = phi i64 [ 0, %6 ], [ %18, %17 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 110
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @fputs(i8* %2, i32* %1)
br label %17
15: ; preds = %8
%16 = tail call i32 @fputc(i8 signext %11, i32* %1)
br label %17
17: ; preds = %13, %15
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %7
br i1 %19, label %20, label %8
20: ; preds = %17, %3
%21 = tail call i32 @fputc(i8 signext 10, i32* %1)
ret void
}