#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 */
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char count_lines(char *txt) {
  int i;
  char *c, buf[4096];
  if (!txt)
    return (char)'0';
  i = 1;
  for (c = txt; *c != '\0'; c++)
    if (*c == '\n')
      i++;
  if (i > 9)
    return (char)'+';
  snprintf(buf, 4096, "%d", i);
  return (buf[0]);
}


x86 assembly (clang, -O0):
<count_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <count_lines+0x23>
movb   $0x30,-0x1(%rbp)
jmp    11b8 <count_lines+0xa8>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1181 <count_lines+0x71>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    116b <count_lines+0x5b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <count_lines+0x60>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1142 <count_lines+0x32>
cmpl   $0x9,-0x14(%rbp)
jle    1194 <count_lines+0x84>
movb   $0x2b,-0x1(%rbp)
jmp    11b8 <count_lines+0xa8>
lea    -0x1020(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x1000,%esi
lea    0xe56(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x1020(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_lines>:
sub    $0x1008,%rsp
test   %rdi,%rdi
je     1168 <count_lines+0x58>
mov    $0x1,%ecx
jmp    1137 <count_lines+0x27>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ecx
add    $0x1,%rdi
movzbl (%rdi),%eax
cmp    $0xa,%al
je     1130 <count_lines+0x20>
test   %al,%al
jne    1133 <count_lines+0x23>
mov    $0x2b,%al
cmp    $0x9,%ecx
jg     1160 <count_lines+0x50>
lea    0xeb0(%rip),%rdx
mov    %rsp,%rdi
mov    $0x1000,%esi
call   1030 <snprintf@plt>
mov    (%rsp),%al
add    $0x1008,%rsp
ret
mov    $0x30,%al
add    $0x1008,%rsp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define signext i8 @count_lines(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [4096 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i8 48, i8* %2
br label %39
10: ; preds = %1
store i32 1, i32* %4
%11 = load i8*, i8** %3
store i8* %11, i8** %5
br label %12
12: ; preds = %26, %10
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %17
br label %26
26: ; preds = %25
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
br label %12
29: ; preds = %12
%30 = load i32, i32* %4
%31 = icmp sgt i32 %30, 9
br i1 %31, label %32, label %33
32: ; preds = %29
store i8 43, i8* %2
br label %39
33: ; preds = %29
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* %4
%36 = call i32 @snprintf(i8* %34, i32 4096, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%38 = load i8, i8* %37
store i8 %38, i8* %2
br label %39
39: ; preds = %33, %32, %9
%40 = load i8, i8* %2
ret i8 %40
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define signext i8 @count_lines(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %19, label %5
5: ; preds = %1, %11
%6 = phi i32 [ %12, %11 ], [ 1, %1 ]
%7 = phi i8* [ %13, %11 ], [ %0, %1 ]
%8 = load i8, i8* %7
switch i8 %8, label %11 [
i8 0, label %14
i8 10, label %9
]
9: ; preds = %5
%10 = add nsw i32 %6, 1
br label %11
11: ; preds = %5, %9
%12 = phi i32 [ %10, %9 ], [ %6, %5 ]
%13 = getelementptr inbounds i8, i8* %7, i64 1
br label %5
14: ; preds = %5
%15 = icmp sgt i32 %6, 9
br i1 %15, label %19, label %16
16: ; preds = %14
%17 = call i32 @snprintf(i8* %3, i32 4096, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
%18 = load i8, i8* %3
br label %19
19: ; preds = %14, %1, %16
%20 = phi i8 [ %18, %16 ], [ 48, %1 ], [ 43, %14 ]
ret i8 %20
}