#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 */
char *strchr(char *, int);
int teleinfo_checksum(char *message) {
  const char *message_oel = strchr(message, 0x0d);
  unsigned char sum = 0;
  message++;
  while ((*message != '\0') && (message != (message_oel - 2))) {
    sum += *message;
    message++;
  }
  sum = (sum & 0x3F) + 0x20;
  message++;
  if (sum == *message) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<teleinfo_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1a(%rbp)
je     1168 <teleinfo_checksum+0x58>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0xfffffffffffffffe,%rcx
cmp    %rcx,%rax
setne  %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    1178 <teleinfo_checksum+0x68>
jmp    1199 <teleinfo_checksum+0x89>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
movzbl -0x19(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113e <teleinfo_checksum+0x2e>
movzbl -0x19(%rbp),%eax
and    $0x3f,%eax
add    $0x20,%eax
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movzbl -0x19(%rbp),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11d1 <teleinfo_checksum+0xc1>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <teleinfo_checksum+0xc8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<teleinfo_checksum>:
push   %rbx
mov    %rdi,%rbx
mov    $0xd,%esi
call   1030 <strchr@plt>
mov    0x1(%rbx),%dl
mov    $0x20,%ecx
test   %dl,%dl
je     1165 <teleinfo_checksum+0x55>
add    $0xfffffffffffffffe,%rax
lea    0x1(%rbx),%rsi
cmp    %rax,%rsi
je     1165 <teleinfo_checksum+0x55>
add    $0x2,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
movzbl %dl,%ecx
add    %edi,%ecx
movzbl (%rsi),%edx
lea    0x1(%rsi),%rbx
test   %dl,%dl
je     115b <teleinfo_checksum+0x4b>
movzbl %cl,%edi
cmp    %rax,%rsi
mov    %rbx,%rsi
jne    1140 <teleinfo_checksum+0x30>
and    $0x3f,%ecx
add    $0x20,%ecx
add    $0xfffffffffffffffe,%rbx
movsbl 0x2(%rbx),%edx
xor    %eax,%eax
cmp    %edx,%ecx
sete   %al
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @teleinfo_checksum(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 13)
%3 = getelementptr inbounds i8, i8* %2, i64 -2
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = icmp ne i8 %5, 0
%7 = icmp ne i8* %4, %3
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %9, label %24
9: ; preds = %1, %9
%10 = phi i8 [ %17, %9 ], [ %5, %1 ]
%11 = phi i8* [ %16, %9 ], [ %4, %1 ]
%12 = phi i32 [ %15, %9 ], [ 0, %1 ]
%13 = zext i8 %10 to i32
%14 = add nuw nsw i32 %12, %13
%15 = and i32 %14, 255
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
%19 = icmp ne i8* %16, %3
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %9, label %21
21: ; preds = %9
%22 = and i32 %14, 63
%23 = add nuw nsw i32 %22, 32
br label %24
24: ; preds = %21, %1
%25 = phi i8* [ %0, %1 ], [ %11, %21 ]
%26 = phi i32 [ 32, %1 ], [ %23, %21 ]
%27 = getelementptr inbounds i8, i8* %25, i64 2
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %26, %29
%31 = zext i1 %30 to i32
ret i32 %31
}