#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 */
typedef char uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ checksum(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
void gen_ROT(uint8_t *b, uint32_t *len) {
  char csum[3] = {'0', '0', '0'};
  int l;
  const char s[] = "$GPROT,12.7,A";
  strcpy(&b[2], s);
  l = strlen(s) + 1 + 2;
  checksum(csum, b, l - 3);
  b[l++] = '*';
  b[l++] = csum[0];
  b[l++] = csum[1];
  b[l++] = '\r';
  b[l++] = '\n';
  b[l] = 0;
  *len = l;
  b[1] = (uint8_t)(l - 2);
}


x86 assembly (clang, -O0):
<gen_ROT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeb9(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xeb1(%rip),%al
mov    %al,-0x11(%rbp)
mov    0xea8(%rip),%rax
mov    %rax,-0x26(%rbp)
mov    0xea6(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xea0(%rip),%ax
mov    %ax,-0x1a(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
lea    -0x26(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x26(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
lea    -0x13(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
sub    $0x3,%edx
call   1050 <checksum@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x2a,(%rax,%rcx,1)
mov    -0x13(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x12(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0xd,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_ROT>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
movb   $0x30,0x6(%rsp)
movw   $0x3030,0x4(%rsp)
movabs $0x412c372e32312c,%rax
mov    %rax,0xe(%rsp)
movabs $0x312c544f52504724,%rax
54 2c 31
mov    %rax,0x8(%rsp)
add    $0x2,%rdi
lea    0x8(%rsp),%r15
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
lea    0x4(%rsp),%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <checksum@plt>
movb   $0x2a,0x3(%rbx,%r12,1)
mov    0x4(%rsp),%al
mov    %al,0x4(%rbx,%r12,1)
mov    0x5(%rsp),%al
lea    0x6(%rbx),%rcx
mov    %al,0x5(%rbx,%r12,1)
movw   $0xa0d,0x6(%r12,%rbx,1)
0a
movb   $0x0,0x8(%r12,%rbx,1)
add    $0x8,%rbx
mov    %ebx,(%r14)
mov    %cl,0x1(%r12)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.gen_ROT.csum = [3 x i8] c"000"
@__const.gen_ROT.s = [14 x i8] c"$GPROT,12.7,A\00"
define void @gen_ROT(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [3 x i8]
%6 = alloca i32
%7 = alloca [14 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = bitcast [3 x i8]* %5 to i8*
%9 = bitcast [14 x i8]* %7 to i8*
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 2
%12 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%13 = call i32 @strcpy(i8* %11, i8* %12)
%14 = getelementptr inbounds [14 x i8], [14 x i8]* %7, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = add nsw i32 %16, 2
store i32 %17, i32* %6
%18 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 3
%22 = call i32 @checksum(i8* %18, i8* %19, i32 %21)
%23 = load i8*, i8** %3
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 42, i8* %27
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%29 = load i8, i8* %28
%30 = load i8*, i8** %3
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
%36 = load i8, i8* %35
%37 = load i8*, i8** %3
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 %36, i8* %41
%42 = load i8*, i8** %3
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 13, i8* %46
%47 = load i8*, i8** %3
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
store i8 10, i8* %51
%52 = load i8*, i8** %3
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 0, i8* %55
%56 = load i32, i32* %6
%57 = load i32*, i32** %4
store i32 %56, i32* %57
%58 = load i32, i32* %6
%59 = sub nsw i32 %58, 2
%60 = trunc i32 %59 to i8
%61 = load i8*, i8** %3
%62 = getelementptr inbounds i8, i8* %61, i64 1
store i8 %60, i8* %62
ret void
}

LLVM IR (-O2):
@__const.gen_ROT.s = [14 x i8] c"$GPROT,12.7,A\00"
define void @gen_ROT(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [3 x i8]
%4 = alloca [14 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds i8, i8* %0, i64 2
%8 = call i32 @strcpy(i8* %7, i8* %6)
%9 = call i32 @strlen(i8* %6)
%10 = add nsw i32 %9, 3
%11 = call i32 @checksum(i8* %5, i8* %0, i32 %9)
%12 = add nsw i32 %9, 4
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 42, i8* %14
%15 = load i8, i8* %5
%16 = add nsw i32 %9, 5
%17 = sext i32 %12 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 %15, i8* %18
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
%20 = load i8, i8* %19
%21 = add nsw i32 %9, 6
%22 = sext i32 %16 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 %20, i8* %23
%24 = add nsw i32 %9, 7
%25 = sext i32 %21 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
store i8 13, i8* %26
%27 = add nsw i32 %9, 8
%28 = sext i32 %24 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 10, i8* %29
%30 = sext i32 %27 to i64
%31 = getelementptr inbounds i8, i8* %0, i64 %30
store i8 0, i8* %31
store i32 %27, i32* %1
%32 = trunc i32 %21 to i8
%33 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %32, i8* %33
ret void
}