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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int isasciistring(int, unsigned char *);
void fwriteessidstr(uint8_t len, unsigned char *essidstr, FILE *fhd) {
  int p;
  if ((len == 0) || (len > 32)) {
    return;
  }
  if (essidstr[0] == 0) {
    return;
  }
  if (isasciistring(len, essidstr) != false) {
    fwrite(essidstr, len, 1, fhd);
    fprintf(fhd, "\n");
  } else {
    fprintf(fhd, "$HEX[");
    for (p = 0; p < len; p++) {
      fprintf(fhd, "%02x", essidstr[p]);
    }
    fprintf(fhd, "]\n");
  }
  return;
}


x86 assembly (clang, -O0):
<fwriteessidstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1157 <fwriteessidstr+0x27>
cmpl   $0x20,-0x4(%rbp)
jle    115c <fwriteessidstr+0x2c>
jmp    121a <fwriteessidstr+0xea>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    1171 <fwriteessidstr+0x41>
jmp    121a <fwriteessidstr+0xea>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <isasciistring@plt>
cmp    $0x0,%eax
je     11b2 <fwriteessidstr+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    -0x18(%rbp),%rdi
lea    0xe66(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1215 <fwriteessidstr+0xe5>
mov    -0x18(%rbp),%rdi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1203 <fwriteessidstr+0xd3>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cb <fwriteessidstr+0x9b>
mov    -0x18(%rbp),%rdi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    121a <fwriteessidstr+0xea>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwriteessidstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
je     117c <fwriteessidstr+0x4c>
mov    %edi,%ebp
cmp    $0x20,%edi
jg     117c <fwriteessidstr+0x4c>
mov    %rsi,%r12
cmpb   $0x0,(%rsi)
je     117c <fwriteessidstr+0x4c>
mov    %rdx,%r14
mov    %ebp,%edi
mov    %r12,%rsi
call   1040 <isasciistring@plt>
test   %eax,%eax
je     1185 <fwriteessidstr+0x55>
mov    %r12,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
lea    0xe97(%rip),%rdi
mov    $0x1,%esi
jmp    11d7 <fwriteessidstr+0xa7>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe74(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
test   %ebp,%ebp
jle    11cb <fwriteessidstr+0x9b>
mov    %ebp,%ebp
lea    0xe5b(%rip),%r15
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%r12,%rbx,1),%edx
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <fwriteessidstr+0x80>
lea    0xe39(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fwrite@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [6 x i8] c"$HEX[\00"
@.str.2 = [5 x i8] c"%02x\00"
@.str.3 = [3 x i8] c"]\0A\00"
define void @fwriteessidstr(i32 %0, i8* %1, i32* %2) {
%4 = icmp eq i32 %0, 0
%5 = icmp sgt i32 %0, 32
%6 = or i1 %4, %5
br i1 %6, label %31, label %7
7: ; preds = %3
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 0
br i1 %9, label %31, label %10
10: ; preds = %7
%11 = tail call i32 @isasciistring(i32 %0, i8* %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i32 @fwrite(i8* %1, i32 %0, i32 1, i32* %2)
%15 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 1, i64 1, i32* %2)
br label %31
16: ; preds = %10
%17 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 5, i64 1, i32* %2)
%18 = icmp sgt i32 %0, 0
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = zext i32 %0 to i64
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 0, %19 ], [ %27, %21 ]
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = add nuw nsw i64 %22, 1
%28 = icmp eq i64 %27, %20
br i1 %28, label %29, label %21
29: ; preds = %21, %16
%30 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %2)
br label %31
31: ; preds = %13, %29, %7, %3
ret void
}