#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 */
char *mud_getline(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *numlineas(char *string) {
  int cnt = 1;
  static char buf[8192 * 2];
  char buf2[8192], tmpb[8192];
  buf[0] = '\0';
  while (*string) {
    string = mud_getline(string, tmpb);
    sprintf(buf2, "%2d. %s\n\r", cnt++, tmpb);
    strcat(buf, buf2);
  }
  return buf;
}


x86 assembly (clang, -O0):
<numlineas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4010,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movb   $0x0,0x2f03(%rip)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ab <numlineas+0x7b>
mov    -0x8(%rbp),%rdi
lea    -0x4010(%rbp),%rsi
call   1030 <mud_getline@plt>
mov    %rax,-0x8(%rbp)
lea    -0x2010(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    -0x4010(%rbp),%rcx
lea    0xe72(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x2010(%rbp),%rsi
lea    0x2eaf(%rip),%rdi
call   1040 <strcat@plt>
jmp    114d <numlineas+0x1d>
lea    0x2e9e(%rip),%rax
add    $0x4010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numlineas>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4008,%rsp
movb   $0x0,0x2f08(%rip)
cmpb   $0x0,(%rdi)
je     11a9 <numlineas+0x79>
mov    %rdi,%rbx
mov    $0x1,%ebp
mov    %rsp,%r14
lea    0x2000(%rsp),%r12
lea    0x2ee9(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <mud_getline@plt>
mov    %rax,%rbx
lea    0x1(%rbp),%r15d
mov    %r12,%rdi
lea    0xe74(%rip),%rsi
mov    %ebp,%edx
mov    %r14,%rcx
call   1050 <sprintf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <strcat@plt>
cmpb   $0x0,(%rbx)
mov    %r15d,%ebp
jne    1170 <numlineas+0x40>
lea    0x2ea0(%rip),%rax
add    $0x4008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@numlineas.buf = internal global [16384 x i8] zeroinitializer
@.str = [10 x i8] c"%2d. %s\0A\0D\00"
define i8* @numlineas(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [8192 x i8]
%5 = alloca [8192 x i8]
store i8* %0, i8** %2
store i32 1, i32* %3
store i8 0, i8* getelementptr inbounds ([16384 x i8], [16384 x i8]* @numlineas.buf, i64 0, i64 0)
br label %6
6: ; preds = %10, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%13 = call i8* @mud_getline(i8* %11, i8* %12)
store i8* %13, i8** %2
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
%17 = getelementptr inbounds [8192 x i8], [8192 x i8]* %5, i64 0, i64 0
%18 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %17)
%19 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%20 = call i32 @strcat(i8* getelementptr inbounds ([16384 x i8], [16384 x i8]* @numlineas.buf, i64 0, i64 0), i8* %19)
br label %6
21: ; preds = %6
ret i8* getelementptr inbounds ([16384 x i8], [16384 x i8]* @numlineas.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@numlineas.buf = internal global [16384 x i8] zeroinitializer
@.str = [10 x i8] c"%2d. %s\0A\0D\00"
define i8* @numlineas(i8* %0) {
%2 = alloca [8192 x i8]
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
store i8 0, i8* getelementptr inbounds ([16384 x i8], [16384 x i8]* @numlineas.buf, i64 0, i64 0)
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %1, %8
%9 = phi i32 [ %12, %8 ], [ 1, %1 ]
%10 = phi i8* [ %11, %8 ], [ %0, %1 ]
%11 = call i8* @mud_getline(i8* %10, i8* %5)
%12 = add nuw nsw i32 %9, 1
%13 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %5)
%14 = call i32 @strcat(i8* getelementptr inbounds ([16384 x i8], [16384 x i8]* @numlineas.buf, i64 0, i64 0), i8* %4)
%15 = load i8, i8* %11
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %8
17: ; preds = %8, %1
ret i8* getelementptr inbounds ([16384 x i8], [16384 x i8]* @numlineas.buf, i64 0, i64 0)
}