#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 u_char;
typedef int /*<<< orphan*/ MD5_CTX;

/* Variables and functions */
int /*<<< orphan*/ MD5_Final(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ MD5_Update(int /*<<< orphan*/ *, char *, int);
void wep_keygen104(const char *str, u_char *keys) {
  MD5_CTX ctx;
  u_char buf[64];
  int i, j;
  j = 0;
  for (i = 0; i < 64; i++) {
    if (str[j] == 0)
      j = 0;
    buf[i] = str[j++];
  }
  MD5_Init(&ctx);
  MD5_Update(&ctx, buf, sizeof buf);
  MD5_Final(buf, &ctx);
  for (i = 0; i < 13; i++) {
    keys[i] = buf[i];
  }
  return;
}


x86 assembly (clang, -O0):
<wep_keygen104>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0x40,-0x64(%rbp)
jge    119f <wep_keygen104+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1174 <wep_keygen104+0x44>
movl   $0x0,-0x68(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x68(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x68(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x64(%rbp),%rax
mov    %cl,-0x60(%rbp,%rax,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    114e <wep_keygen104+0x1e>
lea    -0x14(%rbp),%rdi
call   1040 <MD5_Init@plt>
lea    -0x60(%rbp),%rsi
lea    -0x14(%rbp),%rdi
mov    $0x40,%edx
call   1050 <MD5_Update@plt>
lea    -0x60(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <MD5_Final@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xd,-0x64(%rbp)
jge    11f9 <wep_keygen104+0xc9>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11ce <wep_keygen104+0x9e>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wep_keygen104>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
xor    %eax,%eax
xor    %ecx,%ecx
jmp    1168 <wep_keygen104+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ecx,%rdx
add    $0x1,%ecx
movzbl (%rdi,%rdx,1),%edx
mov    %dl,0x11(%rsp,%rax,1)
add    $0x2,%rax
cmp    $0x40,%rax
je     1197 <wep_keygen104+0x67>
movslq %ecx,%rdx
cmpb   $0x0,(%rdi,%rdx,1)
mov    $0x0,%edx
je     1178 <wep_keygen104+0x48>
mov    %ecx,%edx
movslq %edx,%rdx
movzbl (%rdi,%rdx,1),%ecx
mov    %cl,0x10(%rsp,%rax,1)
cmpb   $0x0,0x1(%rdi,%rdx,1)
mov    $0x0,%ecx
je     1150 <wep_keygen104+0x20>
add    $0x1,%rdx
mov    %edx,%ecx
jmp    1150 <wep_keygen104+0x20>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <MD5_Init@plt>
lea    0x10(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x40,%edx
call   1050 <MD5_Update@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <MD5_Final@plt>
mov    0x10(%rsp),%rax
mov    0x15(%rsp),%rcx
mov    %rax,(%r14)
mov    %rcx,0x5(%r14)
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @wep_keygen104(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %8
store i32 0, i32* %7
br label %9
9: ; preds = %31, %2
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 64
br i1 %11, label %12, label %34
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %12
store i32 0, i32* %8
br label %21
21: ; preds = %20, %12
%22 = load i8*, i8** %3
%23 = load i32, i32* %8
%24 = add nsw i32 %23, 1
store i32 %24, i32* %8
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 %29
store i8 %27, i8* %30
br label %31
31: ; preds = %21
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %9
34: ; preds = %9
%35 = call i32 @MD5_Init(i32* %5)
%36 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%37 = call i32 @MD5_Update(i32* %5, i8* %36, i32 64)
%38 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%39 = call i32 @MD5_Final(i8* %38, i32* %5)
store i32 0, i32* %7
br label %40
40: ; preds = %52, %34
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 13
br i1 %42, label %43, label %55
43: ; preds = %40
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = load i8*, i8** %4
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
br label %52
52: ; preds = %43
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %40
55: ; preds = %40
ret void
}

LLVM IR (-O2):
define void @wep_keygen104(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca [64 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
br label %7
7: ; preds = %7, %2
%8 = phi i64 [ 0, %2 ], [ %31, %7 ]
%9 = phi i32 [ 0, %2 ], [ %26, %7 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
%14 = select i1 %13, i32 0, i32 %9
%15 = add nsw i32 %14, 1
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %8
store i8 %18, i8* %19
%20 = or i64 %8, 1
%21 = sext i32 %15 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
%25 = select i1 %24, i32 0, i32 %15
%26 = add nsw i32 %25, 1
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %20
store i8 %29, i8* %30
%31 = add nuw nsw i64 %8, 2
%32 = icmp eq i64 %31, 64
br i1 %32, label %33, label %7
33: ; preds = %7
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%35 = call i32 @MD5_Init(i32* %3)
%36 = call i32 @MD5_Update(i32* %3, i8* %6, i32 64)
%37 = call i32 @MD5_Final(i8* %6, i32* %3)
ret void
}