#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 */
typedef int u_int32_t;

/* Variables and functions */
char *eliminate_sequences(char const *);
int /*<<< orphan*/ free(char *);
int score_strings(char *, char *, int);
int sscanf(char const *, char *, int *);
void *strchr(char const *, char);
u_int32_t spamsum_match(const char *str1, const char *str2) {
  u_int32_t block_size1, block_size2;
  u_int32_t score = 0;
  char *s1, *s2;
  char *s1_1, *s1_2;
  char *s2_1, *s2_2;
  if (sscanf(str1, "%u:", &block_size1) != 1 ||
      sscanf(str2, "%u:", &block_size2) != 1) {
    return 0;
  }
  if (block_size1 != block_size2 && block_size1 != block_size2 * 2 &&
      block_size2 != block_size1 * 2) {
    return 0;
  }
  str1 = strchr(str1, ':');
  str2 = strchr(str2, ':');
  if (!str1 || !str2) {
    return 0;
  }
  s1 = eliminate_sequences(str1 + 1);
  s2 = eliminate_sequences(str2 + 1);
  if (!s1 || !s2)
    return 0;
  s1_1 = s1;
  s2_1 = s2;
  s1_2 = strchr(s1, ':');
  s2_2 = strchr(s2, ':');
  if (!s1_2 || !s2_2) {
    free(s1);
    free(s2);
    return 0;
  }
  *s1_2++ = 0;
  *s2_2++ = 0;
  if (block_size1 == block_size2) {
    u_int32_t score1, score2;
    score1 = score_strings(s1_1, s2_1, block_size1);
    score2 = score_strings(s1_2, s2_2, block_size2);
    score = ((score1) > (score2) ? (score1) : (score2));
  } else if (block_size1 == block_size2 * 2) {
    score = score_strings(s1_1, s2_2, block_size1);
  } else {
    score = score_strings(s1_2, s2_1, block_size2);
  }
  free(s1);
  free(s2);
  return score;
}


x86 assembly (clang, -O0):
<spamsum_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11a1 <spamsum_match+0x51>
mov    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
je     11ad <spamsum_match+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    13b0 <spamsum_match+0x260>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     11e7 <spamsum_match+0x97>
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
je     11e7 <spamsum_match+0x97>
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
je     11e7 <spamsum_match+0x97>
movl   $0x0,-0x4(%rbp)
jmp    13b0 <spamsum_match+0x260>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1221 <spamsum_match+0xd1>
cmpq   $0x0,-0x18(%rbp)
jne    122d <spamsum_match+0xdd>
movl   $0x0,-0x4(%rbp)
jmp    13b0 <spamsum_match+0x260>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1050 <eliminate_sequences@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1050 <eliminate_sequences@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1265 <spamsum_match+0x115>
cmpq   $0x0,-0x38(%rbp)
jne    1271 <spamsum_match+0x121>
movl   $0x0,-0x4(%rbp)
jmp    13b0 <spamsum_match+0x260>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12bb <spamsum_match+0x16b>
cmpq   $0x0,-0x58(%rbp)
jne    12d9 <spamsum_match+0x189>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b0 <spamsum_match+0x260>
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x48(%rbp)
movb   $0x0,(%rax)
mov    -0x58(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x58(%rbp)
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    1357 <spamsum_match+0x207>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <score_strings@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <score_strings@plt>
mov    %eax,-0x60(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x60(%rbp),%eax
jle    1346 <spamsum_match+0x1f6>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x64(%rbp)
jmp    134c <spamsum_match+0x1fc>
mov    -0x60(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1398 <spamsum_match+0x248>
mov    -0x1c(%rbp),%eax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jne    1380 <spamsum_match+0x230>
mov    -0x40(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <score_strings@plt>
mov    %eax,-0x24(%rbp)
jmp    1393 <spamsum_match+0x243>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <score_strings@plt>
mov    %eax,-0x24(%rbp)
jmp    1398 <spamsum_match+0x248>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spamsum_match>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe98(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1070 <sscanf@plt>
xor    %r12d,%r12d
cmp    $0x1,%eax
jne    12ba <spamsum_match+0x16a>
lea    0xe7b(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    12ba <spamsum_match+0x16a>
mov    0x4(%rsp),%eax
mov    (%rsp),%ecx
cmp    %ecx,%eax
je     11b5 <spamsum_match+0x65>
lea    (%rcx,%rcx,1),%edx
cmp    %edx,%eax
je     11b5 <spamsum_match+0x65>
add    %eax,%eax
cmp    %eax,%ecx
jne    12ba <spamsum_match+0x16a>
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rbp,%rbp
je     12ba <spamsum_match+0x16a>
mov    %rax,%rbx
test   %rax,%rax
je     12ba <spamsum_match+0x16a>
add    $0x1,%rbp
mov    %rbp,%rdi
call   1050 <eliminate_sequences@plt>
mov    %rax,%r14
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <eliminate_sequences@plt>
test   %r14,%r14
je     12ba <spamsum_match+0x16a>
mov    %rax,%r15
test   %rax,%rax
je     12ba <spamsum_match+0x16a>
mov    %r14,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
xor    %r12d,%r12d
test   %rbx,%rbx
je     12aa <spamsum_match+0x15a>
mov    %rax,%rbp
test   %rax,%rax
je     12aa <spamsum_match+0x15a>
mov    %rbx,%rax
mov    %rbp,%rcx
add    $0x1,%rbx
movb   $0x0,(%rax)
add    $0x1,%rbp
movb   $0x0,(%rcx)
mov    0x4(%rsp),%edx
mov    (%rsp),%eax
cmp    %eax,%edx
jne    128b <spamsum_match+0x13b>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <score_strings@plt>
mov    %eax,%r13d
mov    (%rsp),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <score_strings@plt>
mov    %eax,%r12d
cmp    %eax,%r13d
cmovg  %r13d,%r12d
jmp    12aa <spamsum_match+0x15a>
lea    (%rax,%rax,1),%ecx
cmp    %ecx,%edx
jne    129a <spamsum_match+0x14a>
mov    %r14,%rdi
mov    %rbp,%rsi
jmp    12a2 <spamsum_match+0x152>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <score_strings@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%u:\00"
define i32 @spamsum_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %8
%17 = load i8*, i8** %4
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %6)
%19 = icmp ne i32 %18, 1
br i1 %19, label %24, label %20
20: ; preds = %2
%21 = load i8*, i8** %5
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %7)
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %20, %2
store i32 0, i32* %3
br label %129
25: ; preds = %20
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %40
29: ; preds = %25
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = mul nsw i32 %31, 2
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i32, i32* %7
%36 = load i32, i32* %6
%37 = mul nsw i32 %36, 2
%38 = icmp ne i32 %35, %37
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 0, i32* %3
br label %129
40: ; preds = %34, %29, %25
%41 = load i8*, i8** %4
%42 = call i8* @strchr(i8* %41, i8 signext 58)
store i8* %42, i8** %4
%43 = load i8*, i8** %5
%44 = call i8* @strchr(i8* %43, i8 signext 58)
store i8* %44, i8** %5
%45 = load i8*, i8** %4
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = load i8*, i8** %5
%49 = icmp ne i8* %48, null
br i1 %49, label %51, label %50
50: ; preds = %47, %40
store i32 0, i32* %3
br label %129
51: ; preds = %47
%52 = load i8*, i8** %4
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = call i8* @eliminate_sequences(i8* %53)
store i8* %54, i8** %9
%55 = load i8*, i8** %5
%56 = getelementptr inbounds i8, i8* %55, i64 1
%57 = call i8* @eliminate_sequences(i8* %56)
store i8* %57, i8** %10
%58 = load i8*, i8** %9
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %63
60: ; preds = %51
%61 = load i8*, i8** %10
%62 = icmp ne i8* %61, null
br i1 %62, label %64, label %63
63: ; preds = %60, %51
store i32 0, i32* %3
br label %129
64: ; preds = %60
%65 = load i8*, i8** %9
store i8* %65, i8** %11
%66 = load i8*, i8** %10
store i8* %66, i8** %13
%67 = load i8*, i8** %9
%68 = call i8* @strchr(i8* %67, i8 signext 58)
store i8* %68, i8** %12
%69 = load i8*, i8** %10
%70 = call i8* @strchr(i8* %69, i8 signext 58)
store i8* %70, i8** %14
%71 = load i8*, i8** %12
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %76
73: ; preds = %64
%74 = load i8*, i8** %14
%75 = icmp ne i8* %74, null
br i1 %75, label %81, label %76
76: ; preds = %73, %64
%77 = load i8*, i8** %9
%78 = call i32 @free(i8* %77)
%79 = load i8*, i8** %10
%80 = call i32 @free(i8* %79)
store i32 0, i32* %3
br label %129
81: ; preds = %73
%82 = load i8*, i8** %12
%83 = getelementptr inbounds i8, i8* %82, i32 1
store i8* %83, i8** %12
store i8 0, i8* %82
%84 = load i8*, i8** %14
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %14
store i8 0, i8* %84
%86 = load i32, i32* %6
%87 = load i32, i32* %7
%88 = icmp eq i32 %86, %87
br i1 %88, label %89, label %107
89: ; preds = %81
%90 = load i8*, i8** %11
%91 = load i8*, i8** %13
%92 = load i32, i32* %6
%93 = call i32 @score_strings(i8* %90, i8* %91, i32 %92)
store i32 %93, i32* %15
%94 = load i8*, i8** %12
%95 = load i8*, i8** %14
%96 = load i32, i32* %7
%97 = call i32 @score_strings(i8* %94, i8* %95, i32 %96)
store i32 %97, i32* %16
%98 = load i32, i32* %15
%99 = load i32, i32* %16
%100 = icmp sgt i32 %98, %99
br i1 %100, label %101, label %103
101: ; preds = %89
%102 = load i32, i32* %15
br label %105
103: ; preds = %89
%104 = load i32, i32* %16
br label %105
105: ; preds = %103, %101
%106 = phi i32 [ %102, %101 ], [ %104, %103 ]
store i32 %106, i32* %8
br label %123
107: ; preds = %81
%108 = load i32, i32* %6
%109 = load i32, i32* %7
%110 = mul nsw i32 %109, 2
%111 = icmp eq i32 %108, %110
br i1 %111, label %112, label %117
112: ; preds = %107
%113 = load i8*, i8** %11
%114 = load i8*, i8** %14
%115 = load i32, i32* %6
%116 = call i32 @score_strings(i8* %113, i8* %114, i32 %115)
store i32 %116, i32* %8
br label %122
117: ; preds = %107
%118 = load i8*, i8** %12
%119 = load i8*, i8** %13
%120 = load i32, i32* %7
%121 = call i32 @score_strings(i8* %118, i8* %119, i32 %120)
store i32 %121, i32* %8
br label %122
122: ; preds = %117, %112
br label %123
123: ; preds = %122, %105
%124 = load i8*, i8** %9
%125 = call i32 @free(i8* %124)
%126 = load i8*, i8** %10
%127 = call i32 @free(i8* %126)
%128 = load i32, i32* %8
store i32 %128, i32* %3
br label %129
129: ; preds = %123, %76, %63, %50, %39, %24
%130 = load i32, i32* %3
ret i32 %130
}

LLVM IR (-O2):
@.str = [4 x i8] c"%u:\00"
define i32 @spamsum_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %65
9: ; preds = %2
%10 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %4)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %65
12: ; preds = %9
%13 = load i32, i32* %3
%14 = load i32, i32* %4
%15 = icmp eq i32 %13, %14
%16 = shl nsw i32 %14, 1
%17 = icmp eq i32 %13, %16
%18 = select i1 %15, i1 true, i1 %17
%19 = shl nsw i32 %13, 1
%20 = icmp eq i32 %14, %19
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %22, label %65
22: ; preds = %12
%23 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 58)
%24 = call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 58)
%25 = icmp ne i8* %23, null
%26 = icmp ne i8* %24, null
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %28, label %65
28: ; preds = %22
%29 = getelementptr inbounds i8, i8* %23, i64 1
%30 = call i8* @eliminate_sequences(i8* %29)
%31 = getelementptr inbounds i8, i8* %24, i64 1
%32 = call i8* @eliminate_sequences(i8* %31)
%33 = icmp ne i8* %30, null
%34 = icmp ne i8* %32, null
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %36, label %65
36: ; preds = %28
%37 = call i8* @strchr(i8* %30, i8 signext 58)
%38 = call i8* @strchr(i8* %32, i8 signext 58)
%39 = icmp ne i8* %37, null
%40 = icmp ne i8* %38, null
%41 = select i1 %39, i1 %40, i1 false
br i1 %41, label %42, label %61
42: ; preds = %36
%43 = getelementptr inbounds i8, i8* %37, i64 1
store i8 0, i8* %37
%44 = getelementptr inbounds i8, i8* %38, i64 1
store i8 0, i8* %38
%45 = load i32, i32* %3
%46 = load i32, i32* %4
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %42
%49 = call i32 @score_strings(i8* %30, i8* %32, i32 %45)
%50 = load i32, i32* %4
%51 = call i32 @score_strings(i8* %43, i8* %44, i32 %50)
%52 = icmp sgt i32 %49, %51
%53 = select i1 %52, i32 %49, i32 %51
br label %61
54: ; preds = %42
%55 = shl nsw i32 %46, 1
%56 = icmp eq i32 %45, %55
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 @score_strings(i8* %30, i8* %44, i32 %45)
br label %61
59: ; preds = %54
%60 = call i32 @score_strings(i8* %43, i8* %32, i32 %46)
br label %61
61: ; preds = %48, %59, %57, %36
%62 = phi i32 [ 0, %36 ], [ %53, %48 ], [ %58, %57 ], [ %60, %59 ]
%63 = call i32 @free(i8* %30)
%64 = call i32 @free(i8* %32)
br label %65
65: ; preds = %61, %28, %22, %12, %2, %9
%66 = phi i32 [ 0, %9 ], [ 0, %2 ], [ 0, %12 ], [ 0, %22 ], [ 0, %28 ], [ %62, %61 ]
ret i32 %66
}