#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);
int /*<<< orphan*/ memcpy(char *, char *, int);
void wep_keygen128(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);
  memcpy(keys, buf, (13 * 4));
  for (i = 0; i < 13; i++) {
    keys[i] = buf[i];
  }
  for (; i < (13 * 4); i++) {
    keys[i] = 0;
  }
  return;
}


x86 assembly (clang, -O0):
<wep_keygen128>:
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    11af <wep_keygen128+0x6f>
mov    -0x8(%rbp),%rax
movslq -0x68(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1184 <wep_keygen128+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    115e <wep_keygen128+0x1e>
lea    -0x14(%rbp),%rdi
call   1050 <MD5_Init@plt>
lea    -0x60(%rbp),%rsi
lea    -0x14(%rbp),%rdi
mov    $0x40,%edx
call   1060 <MD5_Update@plt>
lea    -0x60(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <MD5_Final@plt>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x34,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xd,-0x64(%rbp)
jge    121b <wep_keygen128+0xdb>
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    11f0 <wep_keygen128+0xb0>
jmp    1220 <wep_keygen128+0xe0>
cmpl   $0x34,-0x64(%rbp)
jge    1244 <wep_keygen128+0x104>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1220 <wep_keygen128+0xe0>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wep_keygen128>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
xor    %ecx,%ecx
jmp    1178 <wep_keygen128+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     11a7 <wep_keygen128+0x67>
movslq %ecx,%rdx
cmpb   $0x0,(%rdi,%rdx,1)
mov    $0x0,%edx
je     1188 <wep_keygen128+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     1160 <wep_keygen128+0x20>
add    $0x1,%rdx
mov    %edx,%ecx
jmp    1160 <wep_keygen128+0x20>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1050 <MD5_Init@plt>
lea    0x10(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x40,%edx
call   1060 <MD5_Update@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <MD5_Final@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x34,%edx
call   1040 <memcpy@plt>
mov    0x10(%rsp),%rax
mov    0x15(%rsp),%rcx
mov    %rax,(%rbx)
mov    %rcx,0x5(%rbx)
xorps  %xmm0,%xmm0
movups %xmm0,0xd(%rbx)
movups %xmm0,0x1d(%rbx)
movq   $0x0,0x2c(%rbx)
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @wep_keygen128(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)
%40 = load i8*, i8** %4
%41 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%42 = call i32 @memcpy(i8* %40, i8* %41, i32 52)
store i32 0, i32* %7
br label %43
43: ; preds = %55, %34
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 13
br i1 %45, label %46, label %58
46: ; preds = %43
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = load i8*, i8** %4
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 %50, i8* %54
br label %55
55: ; preds = %46
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %43
58: ; preds = %43
br label %59
59: ; preds = %67, %58
%60 = load i32, i32* %7
%61 = icmp slt i32 %60, 52
br i1 %61, label %62, label %70
62: ; preds = %59
%63 = load i8*, i8** %4
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
br label %67
67: ; preds = %62
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %59
70: ; preds = %59
ret void
}

LLVM IR (-O2):
define void @wep_keygen128(i8* nocapture %0, i8* %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)
%38 = call i32 @memcpy(i8* %1, i8* %6, i32 52)
%39 = getelementptr i8, i8* %1, i64 13
ret void
}