#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*/ noise;
typedef int /*<<< orphan*/ ioctl_req_version;
typedef int /*<<< orphan*/ ap;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, int *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ wl_ioctl(char const *, int, ...);
int wl_get_noise(const char *ifname, int *buf) {
  unsigned int ap, noise;
  int ioctl_req_version = 0x2000;
  char tmp[8192];
  memset(tmp, 0, 8192);
  memcpy(tmp, &ioctl_req_version, sizeof(ioctl_req_version));
  wl_ioctl(ifname, 136, tmp, 8192);
  if ((wl_ioctl(ifname, 117, &ap, sizeof(ap)) < 0) || ap) {
    if (wl_ioctl(ifname, 135, &noise, sizeof(noise)) < 0)
      noise = 0;
  } else {
    noise = tmp[84];
  }
  *buf = noise;
  return 0;
}


x86 assembly (clang, -O0):
<wl_get_noise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2000,-0x1c(%rbp)
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1030 <memset@plt>
lea    -0x2020(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2020(%rbp),%rdx
mov    $0x88,%esi
mov    $0x2000,%ecx
mov    $0x0,%al
call   1050 <wl_ioctl@plt>
mov    -0x8(%rbp),%rdi
mov    $0x75,%esi
lea    -0x14(%rbp),%rdx
mov    $0x4,%ecx
mov    $0x0,%al
call   1050 <wl_ioctl@plt>
cmp    $0x0,%rax
jl     11bb <wl_get_noise+0x8b>
cmpl   $0x0,-0x14(%rbp)
je     11ea <wl_get_noise+0xba>
mov    -0x8(%rbp),%rdi
mov    $0x87,%esi
lea    -0x18(%rbp),%rdx
mov    $0x4,%ecx
mov    $0x0,%al
call   1050 <wl_ioctl@plt>
cmp    $0x0,%rax
jge    11e5 <wl_get_noise+0xb5>
movl   $0x0,-0x18(%rbp)
jmp    11f4 <wl_get_noise+0xc4>
movsbl -0x1fcc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wl_get_noise>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2018,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x2000,0x4(%rsp)
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1030 <memset@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    %r15,%rdi
mov    $0x88,%esi
mov    %rbx,%rdx
mov    $0x2000,%ecx
xor    %eax,%eax
call   1050 <wl_ioctl@plt>
lea    0xc(%rsp),%rdx
mov    $0x4,%ecx
mov    %r15,%rdi
mov    $0x75,%esi
xor    %eax,%eax
call   1050 <wl_ioctl@plt>
test   %rax,%rax
js     11b6 <wl_get_noise+0x86>
cmpl   $0x0,0xc(%rsp)
jne    11b6 <wl_get_noise+0x86>
movsbl 0x64(%rsp),%ebp
jmp    11d8 <wl_get_noise+0xa8>
lea    0x8(%rsp),%rdx
mov    $0x4,%ecx
mov    %r15,%rdi
mov    $0x87,%esi
xor    %eax,%eax
call   1050 <wl_ioctl@plt>
test   %rax,%rax
js     11d8 <wl_get_noise+0xa8>
mov    0x8(%rsp),%ebp
mov    %ebp,(%r14)
xor    %eax,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wl_get_noise(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8192 x i8]
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 8192, i32* %7
%9 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 8192)
%11 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%12 = call i32 @memcpy(i8* %11, i32* %7, i32 4)
%13 = load i8*, i8** %3
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%15 = call i64 (i8*, i32, ...) @wl_ioctl(i8* %13, i32 136, i8* %14, i32 8192)
%16 = load i8*, i8** %3
%17 = call i64 (i8*, i32, ...) @wl_ioctl(i8* %16, i32 117, i32* %5, i64 4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %2
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19, %2
%23 = load i8*, i8** %3
%24 = call i64 (i8*, i32, ...) @wl_ioctl(i8* %23, i32 135, i32* %6, i64 4)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 0, i32* %6
br label %27
27: ; preds = %26, %22
br label %32
28: ; preds = %19
%29 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 84
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
store i32 %31, i32* %6
br label %32
32: ; preds = %28, %27
%33 = load i32, i32* %6
%34 = load i32*, i32** %4
store i32 %33, i32* %34
ret i32 0
}

LLVM IR (-O2):
define i32 @wl_get_noise(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [8192 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
store i32 8192, i32* %5
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 8192)
%12 = call i32 @memcpy(i8* %10, i32* %5, i32 4)
%13 = call i64 (i8*, i32, ...) @wl_ioctl(i8* %0, i32 136, i8* %10, i32 8192)
%14 = call i64 (i8*, i32, ...) @wl_ioctl(i8* %0, i32 117, i32* %3, i64 4)
%15 = icmp slt i64 %14, 0
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 0
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = call i64 (i8*, i32, ...) @wl_ioctl(i8* %0, i32 135, i32* %4, i64 4)
%21 = icmp slt i64 %20, 0
%22 = load i32, i32* %4
%23 = select i1 %21, i32 0, i32 %22
br label %28
24: ; preds = %2
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* %6, i64 0, i64 84
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
br label %28
28: ; preds = %19, %24
%29 = phi i32 [ %27, %24 ], [ %23, %19 ]
store i32 %29, i32* %1
ret i32 0
}