#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*/ lbuf1;

/* Variables and functions */
int /*<<< orphan*/ snprintf(unsigned char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(unsigned char *, char *, unsigned char *);
void text_number_lines(const unsigned char *intxt, size_t insize,
                       unsigned char *outtxt) {
  unsigned char lbuf1[16];
  size_t i, j = 1;
  unsigned char *s = outtxt;
  snprintf(lbuf1, sizeof(lbuf1),
           "[%"
           "z"
           "u]",
           (j++));
  s += sprintf(s, "%-8s", lbuf1);
  for (i = 0; i < insize; i++) {
    *s++ = intxt[i];
    if (intxt[i] == '\n' && i + 1 != insize) {
      snprintf(lbuf1, sizeof(lbuf1),
               "[%"
               "z"
               "u]",
               (j++));
      s += sprintf(s, "%-8s", lbuf1);
    }
  }
  *s = 0;
}


x86 assembly (clang, -O0):
<text_number_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x1,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
mov    %eax,%ecx
mov    $0x10,%esi
lea    0xe9b(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x48(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe8d(%rip),%rsi
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1247 <text_number_lines+0x127>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x48(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x48(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1231 <text_number_lines+0x111>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
cmp    -0x10(%rbp),%rax
je     1231 <text_number_lines+0x111>
lea    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
mov    %eax,%ecx
mov    $0x10,%esi
lea    0xdf8(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x48(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xdea(%rip),%rsi
call   1040 <sprintf@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
jmp    1236 <text_number_lines+0x116>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1196 <text_number_lines+0x76>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_number_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xec2(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x10,%esi
mov    $0x1,%ecx
call   1030 <snprintf@plt>
lea    0xeaa(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
call   1040 <sprintf@plt>
movslq %eax,%rbx
add    %rbp,%rbx
test   %r14,%r14
je     11ee <text_number_lines+0xce>
lea    -0x1(%r14),%rax
mov    %rax,0x8(%rsp)
mov    $0x2,%ecx
xor    %ebp,%ebp
jmp    1195 <text_number_lines+0x75>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    %rbp,%r14
je     11ee <text_number_lines+0xce>
mov    %rbp,%rax
movzbl (%r15,%rbp,1),%edx
mov    %dl,(%rbx)
add    $0x1,%rbx
add    $0x1,%rbp
cmpb   $0xa,(%r15,%rax,1)
jne    1190 <text_number_lines+0x70>
cmp    %rax,0x8(%rsp)
je     1190 <text_number_lines+0x70>
lea    0x1(%rcx),%r13
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x10,%esi
lea    0xe33(%rip),%rdx
call   1030 <snprintf@plt>
mov    %rbx,%rdi
lea    0xe2a(%rip),%rsi
mov    %r12,%rdx
call   1040 <sprintf@plt>
cltq
add    %rax,%rbx
mov    %r13,%rcx
jmp    1190 <text_number_lines+0x70>
movb   $0x0,(%rbx)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"[%zu]\00"
@.str.1 = [5 x i8] c"%-8s\00"
define void @text_number_lines(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca [16 x i8]
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
store i64 1, i64* %9
%11 = load i8*, i8** %6
store i8* %11, i8** %10
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%13 = load i64, i64* %9
%14 = add i64 %13, 1
store i64 %14, i64* %9
%15 = trunc i64 %13 to i32
%16 = call i32 @snprintf(i8* %12, i32 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i8*, i8** %10
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %10
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8* %22, i8** %10
store i64 0, i64* %8
br label %23
23: ; preds = %58, %3
%24 = load i64, i64* %8
%25 = load i64, i64* %5
%26 = icmp ult i64 %24, %25
br i1 %26, label %27, label %61
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = load i64, i64* %8
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %10
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %10
store i8 %31, i8* %32
%34 = load i8*, i8** %4
%35 = load i64, i64* %8
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp eq i32 %38, 10
br i1 %39, label %40, label %57
40: ; preds = %27
%41 = load i64, i64* %8
%42 = add i64 %41, 1
%43 = load i64, i64* %5
%44 = icmp ne i64 %42, %43
br i1 %44, label %45, label %57
45: ; preds = %40
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%47 = load i64, i64* %9
%48 = add i64 %47, 1
store i64 %48, i64* %9
%49 = trunc i64 %47 to i32
%50 = call i32 @snprintf(i8* %46, i32 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %49)
%51 = load i8*, i8** %10
%52 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%53 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = load i8*, i8** %10
%55 = sext i32 %53 to i64
%56 = getelementptr inbounds i8, i8* %54, i64 %55
store i8* %56, i8** %10
br label %57
57: ; preds = %45, %40, %27
br label %58
58: ; preds = %57
%59 = load i64, i64* %8
%60 = add i64 %59, 1
store i64 %60, i64* %8
br label %23
61: ; preds = %23
%62 = load i8*, i8** %10
store i8 0, i8* %62
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"[%zu]\00"
@.str.1 = [5 x i8] c"%-8s\00"
define void @text_number_lines(i8* nocapture %0, i64 %1, i8* nocapture writeonly %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 1)
%7 = call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %2, i64 %8
%10 = icmp eq i64 %1, 0
br i1 %10, label %34, label %11
11: ; preds = %3, %30
%12 = phi i8* [ %32, %30 ], [ %9, %3 ]
%13 = phi i64 [ %31, %30 ], [ 2, %3 ]
%14 = phi i64 [ %20, %30 ], [ 0, %3 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %16, i8* %12
%18 = load i8, i8* %15
%19 = icmp ne i8 %18, 10
%20 = add nuw i64 %14, 1
%21 = icmp eq i64 %20, %1
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %30, label %23
23: ; preds = %11
%24 = add i64 %13, 1
%25 = trunc i64 %13 to i32
%26 = call i32 @snprintf(i8* %5, i32 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %17, i64 %28
br label %30
30: ; preds = %11, %23
%31 = phi i64 [ %24, %23 ], [ %13, %11 ]
%32 = phi i8* [ %29, %23 ], [ %17, %11 ]
%33 = icmp eq i64 %20, %1
br i1 %33, label %34, label %11
34: ; preds = %30, %3
%35 = phi i8* [ %9, %3 ], [ %32, %30 ]
store i8 0, i8* %35
ret void
}