#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 char_value(char const);
bool is_magic(const char *digits) {
  int sums[5];
  for (size_t i = 0; i < 5; i++) {
    sums[i] = char_value(digits[i]) + char_value(digits[i + 5]) +
              char_value(digits[((i + 1) % 5) + 5]);
    if (i > 0 && sums[i] != sums[i - 1])
      return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<is_magic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x5,-0x38(%rbp)
jae    11db <is_magic+0xcb>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <char_value@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsbl 0x5(%rax,%rcx,1),%edi
call   1030 <char_value@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    $0x5,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x48(%rbp),%rax
movsbl 0x5(%rax,%rdx,1),%edi
call   1030 <char_value@plt>
mov    -0x3c(%rbp),%ecx
add    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
cmpq   $0x0,-0x38(%rbp)
jbe    11c5 <is_magic+0xb5>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
je     11c5 <is_magic+0xb5>
movl   $0x0,-0x4(%rbp)
jmp    11e2 <is_magic+0xd2>
jmp    11ca <is_magic+0xba>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1124 <is_magic+0x14>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_magic>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
movsbl (%rdi),%edi
call   1030 <char_value@plt>
mov    %eax,%r14d
movsbl 0x5(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%ebp
add    %r14d,%ebp
movsbl 0x6(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%r14d
add    %ebp,%r14d
movsbl 0x1(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%ebp
movsbl 0x6(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%ebx
add    %ebp,%ebx
movsbl 0x7(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%ebp
add    %ebx,%ebp
xor    %r15d,%r15d
cmp    %r14d,%ebp
jne    120c <is_magic+0xfc>
movsbl 0x2(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%r14d
movsbl 0x7(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%ebx
add    %r14d,%ebx
movsbl 0x8(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%r12d
add    %ebx,%r12d
cmp    %ebp,%r12d
jne    120c <is_magic+0xfc>
movsbl 0x3(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%ebx
movsbl 0x8(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%ebp
add    %ebx,%ebp
movsbl 0x9(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%r14d
add    %ebp,%r14d
cmp    %r12d,%r14d
jne    120c <is_magic+0xfc>
movsbl 0x4(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%ebx
movsbl 0x9(%r13),%edi
call   1030 <char_value@plt>
mov    %eax,%ebp
movsbl 0x5(%r13),%edi
call   1030 <char_value@plt>
add    %ebx,%ebp
add    %eax,%ebp
xor    %r15d,%r15d
cmp    %r14d,%ebp
sete   %r15b
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_magic(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [5 x i32]
%5 = alloca i64
store i8* %0, i8** %3
store i64 0, i64* %5
br label %6
6: ; preds = %46, %1
%7 = load i64, i64* %5
%8 = icmp ult i64 %7, 5
br i1 %8, label %9, label %49
9: ; preds = %6
%10 = load i8*, i8** %3
%11 = load i64, i64* %5
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = load i8, i8* %12
%14 = call i32 @char_value(i8 signext %13)
%15 = load i8*, i8** %3
%16 = load i64, i64* %5
%17 = add i64 %16, 5
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @char_value(i8 signext %19)
%21 = add nsw i32 %14, %20
%22 = load i8*, i8** %3
%23 = load i64, i64* %5
%24 = add i64 %23, 1
%25 = urem i64 %24, 5
%26 = add i64 %25, 5
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = load i8, i8* %27
%29 = call i32 @char_value(i8 signext %28)
%30 = add nsw i32 %21, %29
%31 = load i64, i64* %5
%32 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 %31
store i32 %30, i32* %32
%33 = load i64, i64* %5
%34 = icmp ugt i64 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %9
%36 = load i64, i64* %5
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = load i64, i64* %5
%40 = sub i64 %39, 1
%41 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = icmp ne i32 %38, %42
br i1 %43, label %44, label %45
44: ; preds = %35
store i32 0, i32* %2
br label %50
45: ; preds = %35, %9
br label %46
46: ; preds = %45
%47 = load i64, i64* %5
%48 = add i64 %47, 1
store i64 %48, i64* %5
br label %6
49: ; preds = %6
store i32 1, i32* %2
br label %50
50: ; preds = %49, %44
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
define i32 @is_magic(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @char_value(i8 signext %2)
%4 = getelementptr inbounds i8, i8* %0, i64 5
%5 = load i8, i8* %4
%6 = tail call i32 @char_value(i8 signext %5)
%7 = add nsw i32 %6, %3
%8 = getelementptr inbounds i8, i8* %0, i64 6
%9 = load i8, i8* %8
%10 = tail call i32 @char_value(i8 signext %9)
%11 = add nsw i32 %7, %10
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
%14 = tail call i32 @char_value(i8 signext %13)
%15 = load i8, i8* %8
%16 = tail call i32 @char_value(i8 signext %15)
%17 = add nsw i32 %16, %14
%18 = getelementptr inbounds i8, i8* %0, i64 7
%19 = load i8, i8* %18
%20 = tail call i32 @char_value(i8 signext %19)
%21 = add nsw i32 %17, %20
%22 = icmp eq i32 %21, %11
br i1 %22, label %23, label %59
23: ; preds = %1
%24 = getelementptr inbounds i8, i8* %0, i64 2
%25 = load i8, i8* %24
%26 = tail call i32 @char_value(i8 signext %25)
%27 = load i8, i8* %18
%28 = tail call i32 @char_value(i8 signext %27)
%29 = add nsw i32 %28, %26
%30 = getelementptr inbounds i8, i8* %0, i64 8
%31 = load i8, i8* %30
%32 = tail call i32 @char_value(i8 signext %31)
%33 = add nsw i32 %29, %32
%34 = icmp eq i32 %33, %21
br i1 %34, label %35, label %59
35: ; preds = %23
%36 = getelementptr inbounds i8, i8* %0, i64 3
%37 = load i8, i8* %36
%38 = tail call i32 @char_value(i8 signext %37)
%39 = load i8, i8* %30
%40 = tail call i32 @char_value(i8 signext %39)
%41 = add nsw i32 %40, %38
%42 = getelementptr inbounds i8, i8* %0, i64 9
%43 = load i8, i8* %42
%44 = tail call i32 @char_value(i8 signext %43)
%45 = add nsw i32 %41, %44
%46 = icmp eq i32 %45, %33
br i1 %46, label %47, label %59
47: ; preds = %35
%48 = getelementptr inbounds i8, i8* %0, i64 4
%49 = load i8, i8* %48
%50 = tail call i32 @char_value(i8 signext %49)
%51 = load i8, i8* %42
%52 = tail call i32 @char_value(i8 signext %51)
%53 = load i8, i8* %4
%54 = tail call i32 @char_value(i8 signext %53)
%55 = add nsw i32 %52, %50
%56 = add nsw i32 %55, %54
%57 = icmp eq i32 %56, %45
%58 = zext i1 %57 to i32
br label %59
59: ; preds = %47, %35, %23, %1
%60 = phi i32 [ 0, %1 ], [ 0, %23 ], [ 0, %35 ], [ %58, %47 ]
ret i32 %60
}