#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 *, int);
int /*<<< orphan*/ strlen(char *);
void addnmeacksum(char *c) {
  int i = 0;
  char *d = c;
  d += strlen(d);
  *d++ = '*';
  *d = 0;
  c++;
  while (*c && *c != '*')
    i ^= *c++;
  i &= 0xff;
  sprintf(++c, "%02X", i);
}


x86 assembly (clang, -O0):
<addnmeacksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2a,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     119e <addnmeacksum+0x7e>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11ae <addnmeacksum+0x8e>
jmp    11cb <addnmeacksum+0xab>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1179 <addnmeacksum+0x59>
mov    -0xc(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x8(%rbp)
mov    -0xc(%rbp),%edx
lea    0xe14(%rip),%rsi
call   1040 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addnmeacksum>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
movw   $0x2a,(%rbx,%rax,1)
add    $0x2,%rbx
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movzbl -0x1(%rbx),%ecx
test   %ecx,%ecx
je     1155 <addnmeacksum+0x35>
cmp    $0x2a,%cl
je     1155 <addnmeacksum+0x35>
xor    %ecx,%eax
add    $0x1,%rbx
jmp    1140 <addnmeacksum+0x20>
movzbl %al,%edx
lea    0xea1(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define void @addnmeacksum(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = call i32 @strlen(i8* %6)
%8 = load i8*, i8** %4
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds i8, i8* %8, i64 %9
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %4
store i8 42, i8* %11
%13 = load i8*, i8** %4
store i8 0, i8* %13
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %2
br label %16
16: ; preds = %28, %1
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 42
br label %26
26: ; preds = %21, %16
%27 = phi i1 [ false, %16 ], [ %25, %21 ]
br i1 %27, label %28, label %35
28: ; preds = %26
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %2
%31 = load i8, i8* %29
%32 = sext i8 %31 to i32
%33 = load i32, i32* %3
%34 = xor i32 %33, %32
store i32 %34, i32* %3
br label %16
35: ; preds = %26
%36 = load i32, i32* %3
%37 = and i32 %36, 255
store i32 %37, i32* %3
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %2
%40 = load i32, i32* %3
%41 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %40)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define void @addnmeacksum(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 1
store i8 42, i8* %4
store i8 0, i8* %5
br label %6
6: ; preds = %11, %1
%7 = phi i32 [ 0, %1 ], [ %13, %11 ]
%8 = phi i8* [ %0, %1 ], [ %9, %11 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 0, label %14
i8 42, label %14
]
11: ; preds = %6
%12 = zext i8 %10 to i32
%13 = xor i32 %7, %12
br label %6
14: ; preds = %6, %6
%15 = and i32 %7, 255
%16 = getelementptr inbounds i8, i8* %8, i64 2
%17 = tail call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
ret void
}