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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
char *realloc(char *, size_t);
char *strchr(int /*<<< orphan*/ *, char);
long strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
long get_count(u_char *front, char delim) {
  size_t retsize = 10;
  char *tab = strchr(front, delim);
  char *ret = malloc(retsize);
  if (ret == NULL)
    err(EXIT_FAILURE, "malloc failed");
  size_t offset = 0;
  assert(tab != NULL);
  tab++;
  while (*tab != '\n') {
    if (offset == retsize) {
      retsize *= 2;
      ret = realloc(ret, retsize);
      if (ret == NULL)
        err(EXIT_FAILURE, "malloc failed");
    }
    ret[offset++] = *tab++;
  }
  ret[offset] = 0;
  long retval = strtol(ret, NULL, 0);
  free(ret);
  return retval;
}


x86 assembly (clang, -O0):
<get_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movq   $0xa,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c8 <get_count+0x58>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1070 <err@plt>
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     127a <get_count+0x10a>
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    124e <get_count+0xde>
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1249 <get_count+0xd9>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
call   1070 <err@plt>
jmp    124e <get_count+0xde>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%dl
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x30(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    11ee <get_count+0x7e>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   1040 <strchr@plt>
mov    %rax,%r14
mov    $0xa,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11aa <get_count+0x3a>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1070 <err@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
cmpb   $0xa,0x1(%r14)
jne    11ef <get_count+0x7f>
xor    %eax,%eax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%ebx
xor    %ebp,%ebp
mov    0x2de3(%rip),%r13
lea    0xdfc(%rip),%r12
jmp    1239 <get_count+0xc9>
mov    0x0(%r13),%edi
mov    %r12,%rsi
call   1070 <err@plt>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%r14,%rbp,1),%ecx
lea    0x1(%rbp),%rax
mov    %cl,(%r15,%rbp,1)
cmpb   $0xa,0x2(%r14,%rbp,1)
mov    %rax,%rbp
je     11c1 <get_count+0x51>
cmp    %rbx,%rbp
jne    1220 <get_count+0xb0>
add    %rbx,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <realloc@plt>
test   %rax,%rax
je     1206 <get_count+0x96>
mov    %rax,%r15
jmp    1220 <get_count+0xb0>

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

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [14 x i8] c"malloc failed\00"
define i64 @get_count(i32* %0, i8 signext %1) {
%3 = tail call i8* @strchr(i32* %0, i8 signext %1)
%4 = tail call dereferenceable_or_null(10) i8* @malloc(i64 10)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @err(i32 %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %6, %2
%10 = icmp ne i8* %3, null
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = getelementptr inbounds i8, i8* %3, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %38, label %16
16: ; preds = %9, %29
%17 = phi i8* [ %35, %29 ], [ %13, %9 ]
%18 = phi i64 [ %31, %29 ], [ 10, %9 ]
%19 = phi i64 [ %33, %29 ], [ 0, %9 ]
%20 = phi i8* [ %30, %29 ], [ %4, %9 ]
%21 = icmp eq i64 %19, %18
br i1 %21, label %22, label %29
22: ; preds = %16
%23 = shl i64 %18, 1
%24 = tail call i8* @realloc(i8* %20, i64 %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @err(i32 %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %22, %26, %16
%30 = phi i8* [ null, %26 ], [ %24, %22 ], [ %20, %16 ]
%31 = phi i64 [ %23, %26 ], [ %23, %22 ], [ %18, %16 ]
%32 = load i8, i8* %17
%33 = add i64 %19, 1
%34 = getelementptr inbounds i8, i8* %30, i64 %19
store i8 %32, i8* %34
%35 = getelementptr inbounds i8, i8* %17, i64 1
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 10
br i1 %37, label %38, label %16
38: ; preds = %29, %9
%39 = phi i8* [ %4, %9 ], [ %30, %29 ]
%40 = phi i64 [ 0, %9 ], [ %33, %29 ]
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8 0, i8* %41
%42 = tail call i64 @strtol(i8* nocapture %39, i32* null, i32 0)
%43 = tail call i32 @free(i8* %39)
ret i64 %42
}