#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 */
scalar_t__ strlen(char *);
int compter_char(char *bufcpy, char c) {
  int areturn = 0;
  int i;
  for (i = 0; i < (int)strlen(bufcpy); ++i) {
    areturn += bufcpy[i] == c ? 1 : 0;
    if (bufcpy[i] == '\n')
      return areturn;
  }
  return areturn;
}


x86 assembly (clang, -O0):
<compter_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11a2 <compter_char+0x92>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
movsbl -0x11(%rbp),%esi
xor    %eax,%eax
mov    $0x1,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    118f <compter_char+0x7f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a8 <compter_char+0x98>
jmp    1194 <compter_char+0x84>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1130 <compter_char+0x20>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compter_char>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <strlen@plt>
test   %eax,%eax
jle    1154 <compter_char+0x44>
movslq %eax,%rcx
xor    %eax,%eax
mov    $0x1,%edx
nopl   (%rax)
mov    %eax,%esi
movzbl -0x1(%rbp,%rdx,1),%ebx
xor    %eax,%eax
cmp    %r14b,%bl
sete   %al
add    %esi,%eax
cmp    $0xa,%bl
je     1156 <compter_char+0x46>
lea    0x1(%rdx),%rsi
cmp    %rcx,%rdx
mov    %rsi,%rdx
jl     1130 <compter_char+0x20>
jmp    1156 <compter_char+0x46>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @compter_char(i8* %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %38, %2
%9 = load i32, i32* %7
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = trunc i64 %11 to i32
%13 = icmp slt i32 %9, %12
br i1 %13, label %14, label %41
14: ; preds = %8
%15 = load i8*, i8** %4
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %20, %22
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 1, i32 0
%26 = load i32, i32* %6
%27 = add nsw i32 %26, %25
store i32 %27, i32* %6
%28 = load i8*, i8** %4
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %37
35: ; preds = %14
%36 = load i32, i32* %6
store i32 %36, i32* %3
br label %43
37: ; preds = %14
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %8
41: ; preds = %8
%42 = load i32, i32* %6
store i32 %42, i32* %3
br label %43
43: ; preds = %41, %35
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
define i32 @compter_char(i8* nocapture %0, i8 signext %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = shl i64 %3, 32
%8 = ashr exact i64 %7, 32
br label %9
9: ; preds = %9, %6
%10 = phi i64 [ %18, %9 ], [ 0, %6 ]
%11 = phi i32 [ %16, %9 ], [ 0, %6 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, %1
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %11, %15
%17 = icmp ne i8 %13, 10
%18 = add nuw nsw i64 %10, 1
%19 = icmp slt i64 %18, %8
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %9, label %21
21: ; preds = %9, %2
%22 = phi i32 [ 0, %2 ], [ %16, %9 ]
ret i32 %22
}