#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 */
char generate_printable_char(unsigned char);
scalar_t__ malloc(int);
int random();
char *generate_ssid(unsigned char malformed) {
  char *ssid = (char *)malloc(256);
  int len = 0;
  int t;
  if (malformed) {
    len = (random() % 256);
  } else {
    len = (random() % 32);
  }
  for (t = 0; t < len; t++)
    ssid[t] = generate_printable_char(malformed);
  ssid[len] = '\x00';
  return ssid;
}


x86 assembly (clang, -O0):
<generate_ssid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpb   $0x0,-0x1(%rbp)
je     1174 <generate_ssid+0x44>
mov    $0x0,%al
call   1030 <random@plt>
mov    $0x100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
jmp    1186 <generate_ssid+0x56>
mov    $0x0,%al
call   1030 <random@plt>
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bd <generate_ssid+0x8d>
movzbl -0x1(%rbp),%edi
call   1050 <generate_printable_char@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    118d <generate_ssid+0x5d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_ssid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x100,%ebx
mov    $0x100,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1030 <random@plt>
test   %r14d,%r14d
mov    $0x20,%ecx
cmovne %ebx,%ecx
cltd
idiv   %ecx
mov    %edx,%r15d
test   %edx,%edx
jle    1194 <generate_ssid+0x64>
mov    %r15d,%r13d
xor    %ebx,%ebx
movzbl %r14b,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1050 <generate_printable_char@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <generate_ssid+0x50>
movslq %r15d,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @generate_ssid(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8 %0, i8* %2
%6 = call i64 @malloc(i32 256)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
store i32 0, i32* %4
%8 = load i8, i8* %2
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 (...) @random()
%12 = srem i32 %11, 256
store i32 %12, i32* %4
br label %16
13: ; preds = %1
%14 = call i32 (...) @random()
%15 = srem i32 %14, 32
store i32 %15, i32* %4
br label %16
16: ; preds = %13, %10
store i32 0, i32* %5
br label %17
17: ; preds = %28, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i8, i8* %2
%23 = call signext i8 @generate_printable_char(i8 zeroext %22)
%24 = load i8*, i8** %3
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, i8* %27
br label %28
28: ; preds = %21
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %17
31: ; preds = %17
%32 = load i8*, i8** %3
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
define i8* @generate_ssid(i8 zeroext %0) {
%2 = tail call i64 @malloc(i32 256)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i8 %0, 0
%5 = tail call i32 (...) @random()
%6 = select i1 %4, i32 32, i32 256
%7 = srem i32 %5, %6
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %15, %11 ]
%13 = tail call signext i8 @generate_printable_char(i8 zeroext %0)
%14 = getelementptr inbounds i8, i8* %3, i64 %12
store i8 %13, i8* %14
%15 = add nuw nsw i64 %12, 1
%16 = icmp eq i64 %15, %10
br i1 %16, label %17, label %11
17: ; preds = %11, %1
%18 = sext i32 %7 to i64
%19 = getelementptr inbounds i8, i8* %3, i64 %18
store i8 0, i8* %19
ret i8* %3
}