#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 */
int /*<<< orphan*/ free(char *);
char gen_byte(int, int);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
void wpa(size_t len, char **password) {
  size_t pos;
  char *buf = NULL;
  buf = (char *)malloc(len);
  for (pos = 0; pos < len; ++pos) {
    buf[pos] = gen_byte(0x20, 0x7E);
  }
  memcpy(*password, buf, len);
  free(buf);
}


x86 assembly (clang, -O0):
<wpa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11a8 <wpa+0x68>
mov    $0x20,%edi
mov    $0x7e,%esi
call   1050 <gen_byte@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116d <wpa+0x2d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wpa>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
call   1060 <malloc@plt>
mov    %rax,%r14
test   %r12,%r12
je     117c <wpa+0x3c>
xor    %ebx,%ebx
nopl   (%rax)
mov    $0x20,%edi
mov    $0x7e,%esi
call   1050 <gen_byte@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <wpa+0x20>
mov    (%r15),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @wpa(i64 %0, i8** %1) {
%3 = alloca i64
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i8*
store i64 %0, i64* %3
store i8** %1, i8*** %4
store i8* null, i8** %6
%7 = load i64, i64* %3
%8 = call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %6
store i64 0, i64* %5
br label %10
10: ; preds = %19, %2
%11 = load i64, i64* %5
%12 = load i64, i64* %3
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = call signext i8 @gen_byte(i32 32, i32 126)
%16 = load i8*, i8** %6
%17 = load i64, i64* %5
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8 %15, i8* %18
br label %19
19: ; preds = %14
%20 = load i64, i64* %5
%21 = add i64 %20, 1
store i64 %21, i64* %5
br label %10
22: ; preds = %10
%23 = load i8**, i8*** %4
%24 = load i8*, i8** %23
%25 = load i8*, i8** %6
%26 = load i64, i64* %3
%27 = call i32 @memcpy(i8* %24, i8* %25, i64 %26)
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
ret void
}

LLVM IR (-O2):
define void @wpa(i64 %0, i8** nocapture %1) {
%3 = tail call i64 @malloc(i64 %0)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %0, 0
br i1 %5, label %12, label %6
6: ; preds = %2, %6
%7 = phi i64 [ %10, %6 ], [ 0, %2 ]
%8 = tail call signext i8 @gen_byte(i32 32, i32 126)
%9 = getelementptr inbounds i8, i8* %4, i64 %7
store i8 %8, i8* %9
%10 = add nuw i64 %7, 1
%11 = icmp eq i64 %10, %0
br i1 %11, label %12, label %6
12: ; preds = %6, %2
%13 = load i8*, i8** %1
%14 = tail call i32 @memcpy(i8* %13, i8* %4, i64 %0)
%15 = tail call i32 @free(i8* %4)
ret void
}