#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 int uint32_t;

/* Variables and functions */
scalar_t__ compute_crc(int, char const);
int /*<<< orphan*/ des(int *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int strlen(char const *);
scalar_t__ strtoul(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
extern void checksum(char *sum, const char *key, const char *buf) {
  uint32_t crc = 0;
  uint32_t lword, irword;
  int idx, buf_len = strlen(buf);
  uint32_t seed = (uint32_t)strtoul(key, NULL, 0);
  for (idx = 0; idx < buf_len; ++idx) {
    crc = (uint32_t)compute_crc(crc, buf[idx]);
  }
  lword = crc;
  irword = seed;
  des(&lword, &irword);
  sprintf(sum, "CK=%08x%08x", lword, irword);
}


x86 assembly (clang, -O0):
<checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11c1 <checksum+0x71>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1050 <compute_crc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1190 <checksum+0x40>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <des@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe15(%rip),%rsi
call   1070 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checksum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    11a8 <checksum+0x58>
mov    %ebp,%r13d
xor    %ebp,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r12,%rbp,1),%esi
mov    %ebx,%edi
call   1050 <compute_crc@plt>
mov    %rax,%rbx
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1190 <checksum+0x40>
mov    %ebx,0x4(%rsp)
mov    %r15d,(%rsp)
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
call   1040 <des@plt>
mov    0x4(%rsp),%edx
mov    (%rsp),%ecx
lea    0xe35(%rip),%rsi
mov    %r14,%rdi
call   1070 <sprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"CK=%08x%08x\00"
define void @checksum(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%13 = load i8*, i8** %6
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %11
%15 = load i8*, i8** %5
%16 = call i64 @strtoul(i8* %15, i32* null, i32 0)
%17 = trunc i64 %16 to i32
store i32 %17, i32* %12
store i32 0, i32* %10
br label %18
18: ; preds = %31, %3
%19 = load i32, i32* %10
%20 = load i32, i32* %11
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i32, i32* %7
%24 = load i8*, i8** %6
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = call i64 @compute_crc(i32 %23, i8 signext %28)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %7
br label %31
31: ; preds = %22
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %18
34: ; preds = %18
%35 = load i32, i32* %7
store i32 %35, i32* %8
%36 = load i32, i32* %12
store i32 %36, i32* %9
%37 = call i32 @des(i32* %8, i32* %9)
%38 = load i8*, i8** %4
%39 = load i32, i32* %8
%40 = load i32, i32* %9
%41 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %39, i32 %40)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"CK=%08x%08x\00"
define void @checksum(i8* nocapture writeonly %0, i8* nocapture %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = tail call i32 @strlen(i8* %2)
%9 = tail call i64 @strtoul(i8* nocapture %1, i32* null, i32 0)
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %24
11: ; preds = %3
%12 = zext i32 %8 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %20, %13 ]
%15 = phi i32 [ 0, %11 ], [ %19, %13 ]
%16 = getelementptr inbounds i8, i8* %2, i64 %14
%17 = load i8, i8* %16
%18 = tail call i64 @compute_crc(i32 %15, i8 signext %17)
%19 = trunc i64 %18 to i32
%20 = add nuw nsw i64 %14, 1
%21 = icmp eq i64 %20, %12
br i1 %21, label %22, label %13
22: ; preds = %13
%23 = trunc i64 %18 to i32
br label %24
24: ; preds = %22, %3
%25 = phi i32 [ 0, %3 ], [ %23, %22 ]
%26 = trunc i64 %9 to i32
store i32 %25, i32* %4
store i32 %26, i32* %5
%27 = call i32 @des(i32* %4, i32* %5)
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29)
ret void
}