#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*/ rate;

/* Variables and functions */
int wl_ioctl(char const *, int, int *, int);
int wl_get_bitrate(const char *ifname, int *buf) {
  int ret = -1;
  int rate = 0;
  if (!(ret = wl_ioctl(ifname, 12, &rate, sizeof(rate))) && (rate > 0))
    *buf = ((rate / 2) * 1000) + ((rate & 1) ? 500 : 0);
  return ret;
}


x86 assembly (clang, -O0):
<wl_get_bitrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xc,%esi
lea    -0x18(%rbp),%rdx
mov    $0x4,%ecx
call   1030 <wl_ioctl@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1187 <wl_get_bitrate+0x77>
cmpl   $0x0,-0x18(%rbp)
jle    1187 <wl_get_bitrate+0x77>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%eax,%ecx
mov    -0x18(%rbp),%esi
and    $0x1,%esi
xor    %eax,%eax
mov    $0x1f4,%edx
cmp    $0x0,%esi
cmovne %edx,%eax
add    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wl_get_bitrate>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdx
mov    $0xc,%esi
mov    $0x4,%ecx
call   1030 <wl_ioctl@plt>
test   %eax,%eax
jne    1159 <wl_get_bitrate+0x49>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jle    1159 <wl_get_bitrate+0x49>
mov    %ecx,%edx
shr    %edx
imul   $0x3e8,%edx,%edx
and    $0x1,%ecx
neg    %ecx
and    $0x1f4,%ecx
add    %edx,%ecx
mov    %ecx,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @wl_get_bitrate(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 -1, i32* %5
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = call i32 @wl_ioctl(i8* %7, i32 12, i32* %6, i32 4)
store i32 %8, i32* %5
%9 = icmp ne i32 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %2
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = load i32, i32* %6
%15 = sdiv i32 %14, 2
%16 = mul nsw i32 %15, 1000
%17 = load i32, i32* %6
%18 = and i32 %17, 1
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 500, i32 0
%22 = add nsw i32 %16, %21
%23 = load i32*, i32** %4
store i32 %22, i32* %23
br label %24
24: ; preds = %13, %10, %2
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
define i32 @wl_get_bitrate(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = call i32 @wl_ioctl(i8* %0, i32 12, i32* %3, i32 4)
%6 = icmp eq i32 %5, 0
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = lshr i32 %7, 1
%12 = mul nsw i32 %11, 1000
%13 = and i32 %7, 1
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i32 0, i32 500
%16 = add nuw nsw i32 %15, %12
store i32 %16, i32* %1
br label %17
17: ; preds = %10, %2
ret i32 %5
}