#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 *bytes2str(size_t, unsigned char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memcpy(unsigned char *, char *, size_t);
int /*<<< orphan*/ verbose(int, char *, ...);
int parse_checksum(char *msgbuf, size_t msglen, size_t *len,
                   unsigned char **buf) {
  if (msglen <= 1) {
    verbose(0, "parse_checksum: bad message size %d\n", (int)msglen);
    exit(1);
  }
  *len = msglen;
  *buf = malloc(msglen);
  memcpy(*buf, msgbuf, msglen);
  {
    char *tmp = bytes2str(*len, *buf);
    verbose(1, "parse_checksum: checksum = %s\n", tmp);
    free(tmp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x1,-0x10(%rbp)
ja     11a3 <parse_checksum+0x43>
mov    -0x10(%rbp),%rax
mov    %eax,%edx
xor    %edi,%edi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1070 <verbose@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1060 <bytes2str@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    $0x1,%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1070 <verbose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_checksum>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%rsi
jbe    11d0 <parse_checksum+0x70>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r12
mov    %rbx,(%rdx)
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
mov    (%r15),%rdi
mov    (%r14),%rsi
call   1060 <bytes2str@plt>
mov    %rax,%rbx
lea    0xe7a(%rip),%rsi
mov    $0x1,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <verbose@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe29(%rip),%rsi
xor    %edi,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <verbose@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"parse_checksum: bad message size %d\0A\00"
@.str.1 = [31 x i8] c"parse_checksum: checksum = %s\0A\00"
define i32 @parse_checksum(i8* %0, i64 %1, i64* %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i8**
%9 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64* %2, i64** %7
store i8** %3, i8*** %8
%10 = load i64, i64* %6
%11 = icmp ule i64 %10, 1
br i1 %11, label %12, label %17
12: ; preds = %4
%13 = load i64, i64* %6
%14 = trunc i64 %13 to i32
%15 = call i32 (i32, i8*, ...) @verbose(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %4
%18 = load i64, i64* %6
%19 = load i64*, i64** %7
store i64 %18, i64* %19
%20 = load i64, i64* %6
%21 = call i8* @malloc(i64 %20)
%22 = load i8**, i8*** %8
store i8* %21, i8** %22
%23 = load i8**, i8*** %8
%24 = load i8*, i8** %23
%25 = load i8*, i8** %5
%26 = load i64, i64* %6
%27 = call i32 @memcpy(i8* %24, i8* %25, i64 %26)
%28 = load i64*, i64** %7
%29 = load i64, i64* %28
%30 = load i8**, i8*** %8
%31 = load i8*, i8** %30
%32 = call i8* @bytes2str(i64 %29, i8* %31)
store i8* %32, i8** %9
%33 = load i8*, i8** %9
%34 = call i32 (i32, i8*, ...) @verbose(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %9
%36 = call i32 @free(i8* %35)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"parse_checksum: bad message size %d\0A\00"
@.str.1 = [31 x i8] c"parse_checksum: checksum = %s\0A\00"
define i32 @parse_checksum(i8* %0, i64 %1, i64* nocapture %2, i8** nocapture %3) {
%5 = icmp ult i64 %1, 2
br i1 %5, label %6, label %10
6: ; preds = %4
%7 = trunc i64 %1 to i32
%8 = tail call i32 (i32, i8*, ...) @verbose(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %4
store i64 %1, i64* %2
%11 = tail call i8* @malloc(i64 %1)
store i8* %11, i8** %3
%12 = tail call i32 @memcpy(i8* %11, i8* %0, i64 %1)
%13 = load i64, i64* %2
%14 = load i8*, i8** %3
%15 = tail call i8* @bytes2str(i64 %13, i8* %14)
%16 = tail call i32 (i32, i8*, ...) @verbose(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = tail call i32 @free(i8* %15)
ret i32 0
}