#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*/ ba();
int /*<<< orphan*/ compchar(char);
char key();
int /*<<< orphan*/ mstore(int, int /*<<< orphan*/);
int /*<<< orphan*/ popc();
void str() {
  char d;
  char c;
  int x = 0;
  ba();
  d = key();
  while (1) {
    c = key();
    if (c == d)
      break;
    compchar(c);
    x++;
  }
  mstore(x, popc());
}


x86 assembly (clang, -O0):
<str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <ba@plt>
mov    $0x0,%al
call   1040 <key@plt>
mov    %al,-0x1(%rbp)
mov    $0x0,%al
call   1040 <key@plt>
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
movsbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jne    118f <str+0x3f>
jmp    11a6 <str+0x56>
movsbl -0x2(%rbp),%edi
call   1050 <compchar@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1170 <str+0x20>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <popc@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%esi
call   1060 <mstore@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <ba@plt>
xor    %eax,%eax
call   1040 <key@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <key@plt>
cmp    %bpl,%al
je     1197 <str+0x47>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1050 <compchar@plt>
add    $0x1,%ebx
xor    %eax,%eax
call   1040 <key@plt>
cmp    %bpl,%al
jne    1180 <str+0x30>
xor    %eax,%eax
call   1070 <popc@plt>
mov    %ebx,%edi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <mstore@plt>

LLVM IR (-O0):
define void @str() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 (...) @ba()
%5 = call signext i8 (...) @key()
store i8 %5, i8* %1
br label %6
6: ; preds = %0, %14
%7 = call signext i8 (...) @key()
store i8 %7, i8* %2
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
%10 = load i8, i8* %1
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %9, %11
br i1 %12, label %13, label %14
13: ; preds = %6
br label %19
14: ; preds = %6
%15 = load i8, i8* %2
%16 = call i32 @compchar(i8 signext %15)
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %6
19: ; preds = %13
%20 = load i32, i32* %3
%21 = call i32 (...) @popc()
%22 = call i32 @mstore(i32 %20, i32 %21)
ret void
}

LLVM IR (-O2):
define void @str() {
%1 = tail call i32 (...) @ba()
%2 = tail call signext i8 (...) @key()
%3 = tail call signext i8 (...) @key()
%4 = icmp eq i8 %3, %2
br i1 %4, label %12, label %5
5: ; preds = %0, %5
%6 = phi i8 [ %10, %5 ], [ %3, %0 ]
%7 = phi i32 [ %9, %5 ], [ 0, %0 ]
%8 = tail call i32 @compchar(i8 signext %6)
%9 = add nuw nsw i32 %7, 1
%10 = tail call signext i8 (...) @key()
%11 = icmp eq i8 %10, %2
br i1 %11, label %12, label %5
12: ; preds = %5, %0
%13 = phi i32 [ 0, %0 ], [ %9, %5 ]
%14 = tail call i32 (...) @popc()
%15 = tail call i32 @mstore(i32 %13, i32 %14)
ret void
}