#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 */
struct pane {
  int dummy;
};
struct mark {
  int dummy;
};

/* Variables and functions */
char *pane_mark_attr(struct pane *, struct mark *, char *);
char *strchr(char *, char);
int count_buttons(struct pane *p, struct mark *m) {
  int cnt = 0;
  char *attr = pane_mark_attr(p, m, "multipart-prev:email:actions");
  if (!attr)
    attr = "hide";
  while (attr) {
    cnt += 1;
    attr = strchr(attr, ':');
    if (attr)
      attr++;
  }
  return cnt;
}


x86 assembly (clang, -O0):
<count_buttons>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xeba(%rip),%rdx
call   1040 <pane_mark_attr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1165 <count_buttons+0x45>
lea    0xebc(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    116a <count_buttons+0x4a>
cmpq   $0x0,-0x20(%rbp)
je     11ac <count_buttons+0x8c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a7 <count_buttons+0x87>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116a <count_buttons+0x4a>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_buttons>:
push   %rbx
lea    0xed8(%rip),%rdx
call   1040 <pane_mark_attr@plt>
test   %rax,%rax
lea    0xee6(%rip),%rdi
cmovne %rax,%rdi
xor    %ebx,%ebx
nopl   (%rax)
add    $0x1,%ebx
mov    $0x3a,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
jne    1140 <count_buttons+0x20>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.pane = type { i32 }
%struct.mark = type { i32 }
@.str = [29 x i8] c"multipart-prev:email:actions\00"
@.str.1 = [5 x i8] c"hide\00"
define i32 @count_buttons(%struct.pane* %0, %struct.mark* %1) {
%3 = alloca %struct.pane*
%4 = alloca %struct.mark*
%5 = alloca i32
%6 = alloca i8*
store %struct.pane* %0, %struct.pane** %3
store %struct.mark* %1, %struct.mark** %4
store i32 0, i32* %5
%7 = load %struct.pane*, %struct.pane** %3
%8 = load %struct.mark*, %struct.mark** %4
%9 = call i8* @pane_mark_attr(%struct.pane* %7, %struct.mark* %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %13
13: ; preds = %12, %2
br label %14
14: ; preds = %27, %13
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %28
17: ; preds = %14
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = load i8*, i8** %6
%21 = call i8* @strchr(i8* %20, i8 signext 58)
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
br label %27
27: ; preds = %24, %17
br label %14
28: ; preds = %14
%29 = load i32, i32* %5
ret i32 %29
}

LLVM IR (-O2):
%struct.pane = type { i32 }
%struct.mark = type { i32 }
@.str = [29 x i8] c"multipart-prev:email:actions\00"
@.str.1 = [5 x i8] c"hide\00"
define i32 @count_buttons(%struct.pane* %0, %struct.mark* %1) {
%3 = tail call i8* @pane_mark_attr(%struct.pane* %0, %struct.mark* %1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3
br label %6
6: ; preds = %2, %6
%7 = phi i8* [ %5, %2 ], [ %12, %6 ]
%8 = phi i32 [ 0, %2 ], [ %9, %6 ]
%9 = add nuw nsw i32 %8, 1
%10 = tail call i8* @strchr(i8* %7, i8 signext 58)
%11 = icmp eq i8* %10, null
%12 = getelementptr inbounds i8, i8* %10, i64 1
br i1 %11, label %13, label %6
13: ; preds = %6
ret i32 %9
}