#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 /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ key;

/* Variables and functions */
char *bin2hex(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ md5(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
size_t strlen(char *);
void gen_wep128(char passw[]) {
  size_t len = strlen(passw);
  uint8_t dgst[16];
  char key[128];
  int i;
  memset(key, 0, sizeof(key));
  if (len != 0) {
    for (i = 0; i < 64; i++) {
      key[i] = passw[i % len];
    }
  }
  md5(key, dgst);
  printf("\n  128-Bit WEP Key : %s\n", bin2hex(dgst, key, 13));
}


x86 assembly (clang, -O0):
<gen_wep128>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11ec <gen_wep128+0x9c>
movl   $0x0,-0xd4(%rbp)
cmpl   $0x40,-0xd4(%rbp)
jge    11e7 <gen_wep128+0x97>
mov    -0x8(%rbp),%rax
mov    %rax,-0xe0(%rbp)
movslq -0xd4(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x10(%rbp)
mov    -0xe0(%rbp),%rax
mov    (%rax,%rdx,1),%cl
movslq -0xd4(%rbp),%rax
mov    %cl,-0xd0(%rbp,%rax,1)
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    1194 <gen_wep128+0x44>
jmp    11ec <gen_wep128+0x9c>
lea    -0xd0(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1070 <md5@plt>
lea    -0x50(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
mov    $0xd,%edx
call   1060 <bin2hex@plt>
mov    %rax,%rsi
lea    0xde5(%rip),%rdi
call   1040 <printf@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_wep128>:
push   %r14
push   %rbx
sub    $0xc8,%rsp
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
test   %rbx,%rbx
je     11d4 <gen_wep128+0x84>
xor    %ecx,%ecx
jmp    1198 <gen_wep128+0x48>
nopl   (%rax)
xor    %edx,%edx
div    %rbx
movzbl (%r14,%rdx,1),%eax
mov    %al,0x1(%rsp,%rcx,1)
add    $0x2,%rcx
cmp    $0x40,%rcx
je     11d4 <gen_wep128+0x84>
mov    %rcx,%rax
or     %rbx,%rax
shr    $0x20,%rax
je     11b0 <gen_wep128+0x60>
mov    %rcx,%rax
xor    %edx,%edx
div    %rbx
jmp    11b6 <gen_wep128+0x66>
xchg   %ax,%ax
mov    %ecx,%eax
xor    %edx,%edx
div    %ebx
movzbl (%r14,%rdx,1),%eax
mov    %al,(%rsp,%rcx,1)
lea    0x1(%rcx),%rax
mov    %rax,%rdx
or     %rbx,%rdx
shr    $0x20,%rdx
jne    1180 <gen_wep128+0x30>
xor    %edx,%edx
div    %ebx
jmp    1185 <gen_wep128+0x35>
mov    %rsp,%r14
lea    0x80(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <md5@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xd,%edx
call   1060 <bin2hex@plt>
lea    0xdff(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"\0A 128-Bit WEP Key : %s\0A\00"
define void @gen_wep128(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca [16 x i32]
%5 = alloca [128 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %3
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 128)
%11 = load i64, i64* %3
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %1
store i32 0, i32* %6
br label %14
14: ; preds = %28, %13
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 64
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load i8*, i8** %2
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = load i64, i64* %3
%22 = urem i64 %20, %21
%23 = getelementptr inbounds i8, i8* %18, i64 %22
%24 = load i8, i8* %23
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 %26
store i8 %24, i8* %27
br label %28
28: ; preds = %17
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %14
31: ; preds = %14
br label %32
32: ; preds = %31, %1
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%34 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 0
%35 = call i32 @md5(i8* %33, i32* %34)
%36 = getelementptr inbounds [16 x i32], [16 x i32]* %4, i64 0, i64 0
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%38 = call i8* @bin2hex(i32* %36, i8* %37, i32 13)
%39 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %38)
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"\0A 128-Bit WEP Key : %s\0A\00"
define void @gen_wep128(i8* nocapture %0) {
%2 = alloca [16 x i32]
%3 = alloca [128 x i8]
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = bitcast [16 x i32]* %2 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 128)
%8 = icmp eq i64 %4, 0
br i1 %8, label %22, label %9
9: ; preds = %1, %9
%10 = phi i64 [ %20, %9 ], [ 0, %1 ]
%11 = urem i64 %10, %4
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %10
store i8 %13, i8* %14
%15 = or i64 %10, 1
%16 = urem i64 %15, %4
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %15
store i8 %18, i8* %19
%20 = add nuw nsw i64 %10, 2
%21 = icmp eq i64 %20, 64
br i1 %21, label %22, label %9
22: ; preds = %9, %1
%23 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 0
%24 = call i32 @md5(i8* %6, i32* %23)
%25 = call i8* @bin2hex(i32* %23, i8* %6, i32 13)
%26 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %25)
ret void
}