#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 *, unsigned char);
char *checksum(const char *str) {
  unsigned char cs = 0;
  const char *ptr;
  static char csstr[4];
  for (ptr = str + 1; *ptr; ptr++)
    cs ^= *ptr;
  sprintf(csstr, "*%02hhX", cs % 256);
  return csstr;
}


x86 assembly (clang, -O0):
<checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     115a <checksum+0x4a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
movzbl -0x9(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x9(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112c <checksum+0x1c>
movzbl -0x9(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %dl,%al
lea    0x2eba(%rip),%rdi
lea    0xe8a(%rip),%rsi
movzbl %al,%edx
call   1030 <sprintf@plt>
lea    0x2ea4(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checksum>:
push   %rbx
add    $0x1,%rdi
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
mov    %ecx,%eax
movzbl (%rdi),%edx
mov    %edx,%ecx
xor    %al,%cl
add    $0x1,%rdi
test   %dl,%dl
jne    1120 <checksum+0x10>
movzbl %al,%edx
lea    0x2eee(%rip),%rbx
lea    0xebe(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@checksum.csstr = internal global [4 x i8] zeroinitializer
@.str = [8 x i8] c"*%02hhX\00"
define i8* @checksum(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8*
store i8* %0, i8** %2
store i8 0, i8* %3
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 1
store i8* %6, i8** %4
br label %7
7: ; preds = %19, %1
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = load i8, i8* %3
%16 = zext i8 %15 to i32
%17 = xor i32 %16, %14
%18 = trunc i32 %17 to i8
store i8 %18, i8* %3
br label %19
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
br label %7
22: ; preds = %7
%23 = load i8, i8* %3
%24 = zext i8 %23 to i32
%25 = srem i32 %24, 256
%26 = trunc i32 %25 to i8
%27 = call i32 @sprintf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @checksum.csstr, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 zeroext %26)
ret i8* getelementptr inbounds ([4 x i8], [4 x i8]* @checksum.csstr, i64 0, i64 0)
}

LLVM IR (-O2):
@checksum.csstr = internal global [4 x i8] zeroinitializer
@.str = [8 x i8] c"*%02hhX\00"
define i8* @checksum(i8* nocapture %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8 [ 0, %1 ], [ %8, %2 ]
%4 = phi i8* [ %0, %1 ], [ %5, %2 ]
%5 = getelementptr inbounds i8, i8* %4, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = xor i8 %6, %3
br i1 %7, label %9, label %2
9: ; preds = %2
%10 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @checksum.csstr, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 zeroext %3)
ret i8* getelementptr inbounds ([4 x i8], [4 x i8]* @checksum.csstr, i64 0, i64 0)
}