#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 /*<<< orphan*/ sprintf(char *, char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
int checksum(char *line) {
  char *ptr = &line[0];
  char calculated_sum = 0;
  while (*ptr != '\0' && *ptr != '*') {
    calculated_sum ^= *ptr;
    ptr++;
  }
  char original_sum[3] = "";
  if (*ptr == '*') {
    ptr++;
    int i;
    for (i = 0; *ptr != '\0' && *ptr != '\r'; i++, ptr++) {
      original_sum[i] = *ptr;
    }
    original_sum[i + 1] = '\0';
  }
  char calculated_sum_hex[3];
  sprintf(calculated_sum_hex, "%02X", calculated_sum);
  return !strcmp(original_sum, calculated_sum_hex);
}


x86 assembly (clang, -O0):
<checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1c(%rbp)
je     116d <checksum+0x3d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
setne  %al
mov    %al,-0x1c(%rbp)
mov    -0x1c(%rbp),%al
test   $0x1,%al
jne    117d <checksum+0x4d>
jmp    119e <checksum+0x6e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
movsbl -0x11(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1148 <checksum+0x18>
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
jne    123b <checksum+0x10b>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     11f6 <checksum+0xc6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1206 <checksum+0xd6>
jmp    122e <checksum+0xfe>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x14(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11d1 <checksum+0xa1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x14(%rbp,%rax,1)
lea    -0x1b(%rbp),%rdi
lea    0xdba(%rip),%rsi
movsbl -0x11(%rbp),%edx
call   1050 <sprintf@plt>
lea    -0x14(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checksum>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movzbl (%rdi),%ecx
test   %cl,%cl
je     1144 <checksum+0x24>
cmp    $0x2a,%cl
je     1144 <checksum+0x24>
xor    %cl,%al
add    $0x1,%rdi
jmp    1130 <checksum+0x10>
movb   $0x0,0xc(%rsp)
movw   $0x0,0xa(%rsp)
cmp    $0x2a,%cl
jne    117e <checksum+0x5e>
mov    $0x1,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%rdi,%rcx,1),%edx
test   %dl,%dl
je     1177 <checksum+0x57>
cmp    $0xd,%dl
je     1177 <checksum+0x57>
mov    %dl,0x9(%rsp,%rcx,1)
add    $0x1,%rcx
jmp    1160 <checksum+0x40>
mov    %ecx,%ecx
movb   $0x0,0xa(%rsp,%rcx,1)
movsbl %al,%edx
lea    0xe78(%rip),%rsi
lea    0xd(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
lea    0xa(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define i32 @checksum(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [3 x i8]
%6 = alloca i32
%7 = alloca [3 x i8]
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8* %9, i8** %3
store i8 0, i8* %4
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* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 42
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* %4
%27 = sext i8 %26 to i32
%28 = xor i32 %27, %25
%29 = trunc i32 %28 to i8
store i8 %29, i8* %4
%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 = bitcast [3 x i8]* %5 to i8*
%34 = load i8*, i8** %3
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 42
br i1 %37, label %38, label %69
38: ; preds = %32
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %3
store i32 0, i32* %6
br label %41
41: ; preds = %59, %38
%42 = load i8*, i8** %3
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = load i8*, i8** %3
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 13
br label %51
51: ; preds = %46, %41
%52 = phi i1 [ false, %41 ], [ %50, %46 ]
br i1 %52, label %53, label %64
53: ; preds = %51
%54 = load i8*, i8** %3
%55 = load i8, i8* %54
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 %57
store i8 %55, i8* %58
br label %59
59: ; preds = %53
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
%62 = load i8*, i8** %3
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %3
br label %41
64: ; preds = %51
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 %67
store i8 0, i8* %68
br label %69
69: ; preds = %64, %32
%70 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%71 = load i8, i8* %4
%72 = call i32 @sprintf(i8* %70, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %71)
%73 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%74 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0, i64 0
%75 = call i32 @strcmp(i8* %73, i8* %74)
%76 = icmp ne i32 %75, 0
%77 = xor i1 %76, true
%78 = zext i1 %77 to i32
ret i32 %78
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define i32 @checksum(i8* nocapture %0) {
%2 = alloca [3 x i8]
%3 = alloca [3 x i8]
br label %4
4: ; preds = %8, %1
%5 = phi i8* [ %0, %1 ], [ %10, %8 ]
%6 = phi i8 [ 0, %1 ], [ %9, %8 ]
%7 = load i8, i8* %5
switch i8 %7, label %8 [
i8 0, label %11
i8 42, label %11
]
8: ; preds = %4
%9 = xor i8 %7, %6
%10 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
11: ; preds = %4, %4
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%13 = icmp eq i8 %7, 42
br i1 %13, label %14, label %26
14: ; preds = %11, %19
%15 = phi i64 [ %21, %19 ], [ 0, %11 ]
%16 = phi i8* [ %17, %19 ], [ %5, %11 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
switch i8 %18, label %19 [
i8 0, label %22
i8 13, label %22
]
19: ; preds = %14
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 %15
store i8 %18, i8* %20
%21 = add nuw i64 %15, 1
br label %14
22: ; preds = %14, %14
%23 = add i64 %15, 1
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %22, %11
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%28 = call i32 @sprintf(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %6)
%29 = call i32 @strcmp(i8* %12, i8* %27)
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
ret i32 %31
}