#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 filter_mask {
  int dummy;
};

/* Variables and functions */
unsigned int format_raw_mask(struct filter_mask const *, unsigned int, char *);
scalar_t__ format_readable_mask(struct filter_mask const *, unsigned int,
                                char *, unsigned int);
scalar_t__ strlen(char *);
unsigned int format_mask(const struct filter_mask *mask,
                         unsigned int fa_entry_count, char *buffer) {
  if (format_readable_mask(mask, fa_entry_count, buffer, fa_entry_count / 4))
    return (unsigned int)strlen(buffer);
  else {
    buffer[0] = 'R';
    return format_raw_mask(mask, fa_entry_count, buffer + 1);
  }
}


x86 assembly (clang, -O0):
<format_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
shr    $0x2,%ecx
call   1040 <format_readable_mask@plt>
cmp    $0x0,%rax
je     1174 <format_mask+0x44>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    1192 <format_mask+0x62>
mov    -0x20(%rbp),%rax
movb   $0x52,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
call   1050 <format_raw_mask@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_mask>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%ecx
shr    $0x2,%ecx
call   1040 <format_readable_mask@plt>
test   %rax,%rax
je     1157 <format_mask+0x27>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <strlen@plt>
movb   $0x52,(%rbx)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <format_raw_mask@plt>

LLVM IR (-O0):
%struct.filter_mask = type { i32 }
define i32 @format_mask(%struct.filter_mask* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.filter_mask*
%6 = alloca i32
%7 = alloca i8*
store %struct.filter_mask* %0, %struct.filter_mask** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%8 = load %struct.filter_mask*, %struct.filter_mask** %5
%9 = load i32, i32* %6
%10 = load i8*, i8** %7
%11 = load i32, i32* %6
%12 = udiv i32 %11, 4
%13 = call i64 @format_readable_mask(%struct.filter_mask* %8, i32 %9, i8* %10, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i8*, i8** %7
%17 = call i64 @strlen(i8* %16)
%18 = trunc i64 %17 to i32
store i32 %18, i32* %4
br label %27
19: ; preds = %3
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 82, i8* %21
%22 = load %struct.filter_mask*, %struct.filter_mask** %5
%23 = load i32, i32* %6
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i32 @format_raw_mask(%struct.filter_mask* %22, i32 %23, i8* %25)
store i32 %26, i32* %4
br label %27
27: ; preds = %19, %15
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
%struct.filter_mask = type { i32 }
define i32 @format_mask(%struct.filter_mask* %0, i32 %1, i8* %2) {
%4 = lshr i32 %1, 2
%5 = tail call i64 @format_readable_mask(%struct.filter_mask* %0, i32 %1, i8* %2, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%9 = trunc i64 %8 to i32
br label %13
10: ; preds = %3
store i8 82, i8* %2
%11 = getelementptr inbounds i8, i8* %2, i64 1
%12 = tail call i32 @format_raw_mask(%struct.filter_mask* %0, i32 %1, i8* %11)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ %9, %7 ], [ %12, %10 ]
ret i32 %14
}