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

/* Variables and functions */
scalar_t__ rb_memcicmp(char const *, char *, long);
long parser_encode_length(struct parser_params *parser, const char *name,
                          long len) {
  long nlen;
  if (len > 5 && name[nlen = len - 5] == '-') {
    if (rb_memcicmp(name + nlen + 1, "unix", 4) == 0)
      return nlen;
  }
  if (len > 4 && name[nlen = len - 4] == '-') {
    if (rb_memcicmp(name + nlen + 1, "dos", 3) == 0)
      return nlen;
    if (rb_memcicmp(name + nlen + 1, "mac", 3) == 0 &&
        !(len == 8 && rb_memcicmp(name, "utf8-mac", len) == 0))
      return nlen;
  }
  return len;
}


x86 assembly (clang, -O0):
<parser_encode_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x5,-0x20(%rbp)
jle    1185 <parser_encode_length+0x75>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x5,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    1185 <parser_encode_length+0x75>
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
lea    0xea1(%rip),%rsi
mov    $0x4,%edx
call   1030 <rb_memcicmp@plt>
cmp    $0x0,%rax
jne    1180 <parser_encode_length+0x70>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124b <parser_encode_length+0x13b>
jmp    1185 <parser_encode_length+0x75>
cmpq   $0x4,-0x20(%rbp)
jle    1243 <parser_encode_length+0x133>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x4,%rcx
mov    %rcx,-0x28(%rbp)
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    1243 <parser_encode_length+0x133>
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
lea    0xe45(%rip),%rsi
mov    $0x3,%edx
call   1030 <rb_memcicmp@plt>
cmp    $0x0,%rax
jne    11e1 <parser_encode_length+0xd1>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124b <parser_encode_length+0x13b>
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x1,%rdi
lea    0xe1a(%rip),%rsi
mov    $0x3,%edx
call   1030 <rb_memcicmp@plt>
cmp    $0x0,%rax
jne    123e <parser_encode_length+0x12e>
cmpq   $0x8,-0x20(%rbp)
jne    1231 <parser_encode_length+0x121>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xde7(%rip),%rsi
call   1030 <rb_memcicmp@plt>
cmp    $0x0,%rax
je     123e <parser_encode_length+0x12e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124b <parser_encode_length+0x13b>
jmp    1243 <parser_encode_length+0x133>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parser_encode_length>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
cmp    $0x6,%rdx
jl     1154 <parser_encode_length+0x44>
cmpb   $0x2d,-0x5(%r14,%rbx,1)
jne    115a <parser_encode_length+0x4a>
lea    (%r14,%rbx,1),%rdi
add    $0xfffffffffffffffb,%rdi
add    $0x1,%rdi
lea    0xec1(%rip),%rsi
mov    $0x4,%edx
call   1030 <rb_memcicmp@plt>
test   %rax,%rax
jne    115a <parser_encode_length+0x4a>
add    $0xfffffffffffffffb,%rbx
jmp    11a4 <parser_encode_length+0x94>
cmp    $0x5,%rbx
jne    11a4 <parser_encode_length+0x94>
cmpb   $0x2d,-0x4(%r14,%rbx,1)
jne    11a4 <parser_encode_length+0x94>
lea    -0x4(%rbx),%r15
lea    (%r14,%rbx,1),%r12
add    $0xfffffffffffffffc,%r12
add    $0x1,%r12
lea    0xe8c(%rip),%rsi
mov    $0x3,%edx
mov    %r12,%rdi
call   1030 <rb_memcicmp@plt>
test   %rax,%rax
je     11a7 <parser_encode_length+0x97>
lea    0xe7c(%rip),%rsi
mov    $0x3,%edx
mov    %r12,%rdi
call   1030 <rb_memcicmp@plt>
test   %rax,%rax
je     11b6 <parser_encode_length+0xa6>
mov    %rbx,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
cmp    $0x8,%rbx
jne    11a7 <parser_encode_length+0x97>
lea    0xe46(%rip),%rsi
mov    $0x8,%edx
mov    %r14,%rdi
call   1030 <rb_memcicmp@plt>
mov    $0x4,%r15d
test   %rax,%rax
jne    11a7 <parser_encode_length+0x97>
jmp    11a4 <parser_encode_length+0x94>

LLVM IR (-O0):
%struct.parser_params = type { i32 }
@.str = [5 x i8] c"unix\00"
@.str.1 = [4 x i8] c"dos\00"
@.str.2 = [4 x i8] c"mac\00"
@.str.3 = [9 x i8] c"utf8-mac\00"
define i64 @parser_encode_length(%struct.parser_params* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca %struct.parser_params*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store %struct.parser_params* %0, %struct.parser_params** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i64, i64* %7
%10 = icmp sgt i64 %9, 5
br i1 %10, label %11, label %29
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = load i64, i64* %7
%14 = sub nsw i64 %13, 5
store i64 %14, i64* %8
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 45
br i1 %18, label %19, label %29
19: ; preds = %11
%20 = load i8*, i8** %6
%21 = load i64, i64* %8
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = call i64 @rb_memcicmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %19
%27 = load i64, i64* %8
store i64 %27, i64* %4
br label %69
28: ; preds = %19
br label %29
29: ; preds = %28, %11, %3
%30 = load i64, i64* %7
%31 = icmp sgt i64 %30, 4
br i1 %31, label %32, label %67
32: ; preds = %29
%33 = load i8*, i8** %6
%34 = load i64, i64* %7
%35 = sub nsw i64 %34, 4
store i64 %35, i64* %8
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 45
br i1 %39, label %40, label %67
40: ; preds = %32
%41 = load i8*, i8** %6
%42 = load i64, i64* %8
%43 = getelementptr inbounds i8, i8* %41, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = call i64 @rb_memcicmp(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 3)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %40
%48 = load i64, i64* %8
store i64 %48, i64* %4
br label %69
49: ; preds = %40
%50 = load i8*, i8** %6
%51 = load i64, i64* %8
%52 = getelementptr inbounds i8, i8* %50, i64 %51
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = call i64 @rb_memcicmp(i8* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %66
56: ; preds = %49
%57 = load i64, i64* %7
%58 = icmp eq i64 %57, 8
br i1 %58, label %59, label %64
59: ; preds = %56
%60 = load i8*, i8** %6
%61 = load i64, i64* %7
%62 = call i64 @rb_memcicmp(i8* %60, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %59, %56
%65 = load i64, i64* %8
store i64 %65, i64* %4
br label %69
66: ; preds = %59, %49
br label %67
67: ; preds = %66, %32, %29
%68 = load i64, i64* %7
store i64 %68, i64* %4
br label %69
69: ; preds = %67, %64, %47, %26
%70 = load i64, i64* %4
ret i64 %70
}

LLVM IR (-O2):
%struct.parser_params = type { i32 }
@.str = [5 x i8] c"unix\00"
@.str.1 = [4 x i8] c"dos\00"
@.str.2 = [4 x i8] c"mac\00"
@.str.3 = [9 x i8] c"utf8-mac\00"
define i64 @parser_encode_length(%struct.parser_params* nocapture readnone %0, i8* %1, i64 %2) {
%4 = icmp sgt i64 %2, 5
br i1 %4, label %5, label %14
5: ; preds = %3
%6 = add nsw i64 %2, -5
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 45
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = tail call i64 @rb_memcicmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %34, label %16
14: ; preds = %3
%15 = icmp eq i64 %2, 5
br i1 %15, label %16, label %33
16: ; preds = %5, %10, %14
%17 = add nsw i64 %2, -4
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 45
br i1 %20, label %21, label %33
21: ; preds = %16
%22 = getelementptr inbounds i8, i8* %18, i64 1
%23 = tail call i64 @rb_memcicmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %34, label %25
25: ; preds = %21
%26 = tail call i64 @rb_memcicmp(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = icmp eq i64 %2, 8
br i1 %29, label %30, label %34
30: ; preds = %28
%31 = tail call i64 @rb_memcicmp(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 8)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %25, %30, %16, %14
br label %34
34: ; preds = %28, %30, %21, %10, %33
%35 = phi i64 [ %2, %33 ], [ %6, %10 ], [ %17, %21 ], [ 4, %30 ], [ %17, %28 ]
ret i64 %35
}