#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 ur_dev;

/* Variables and functions */
int device_channels(int);
int read_audio_state(int, int, int /*<<< orphan*/, float *);
int device_gains(int ur_dev) {
  float val[1];
  int err;
  int dev;
  dev = ((ur_dev)&0xffff);
  if ((dev == 13) || (dev == 14)) {
    err = read_audio_state(ur_dev, 2, 0, val);
    return ((int)val[0]);
  }
  err = read_audio_state(ur_dev, 0, 0, val);
  if (err != 0)
    return (0);
  return (device_channels(ur_dev));
}


x86 assembly (clang, -O0):
<device_gains>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xd,-0x14(%rbp)
je     114a <device_gains+0x2a>
cmpl   $0xe,-0x14(%rbp)
jne    116d <device_gains+0x4d>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rcx
mov    $0x2,%esi
xor    %edx,%edx
call   1030 <read_audio_state@plt>
mov    %eax,-0x10(%rbp)
cvttss2si -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a1 <device_gains+0x81>
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rcx
xor    %edx,%edx
mov    %edx,%esi
call   1030 <read_audio_state@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1196 <device_gains+0x76>
movl   $0x0,-0x4(%rbp)
jmp    11a1 <device_gains+0x81>
mov    -0x8(%rbp),%edi
call   1040 <device_channels@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<device_gains>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
movzwl %bx,%eax
add    $0xfffffff3,%eax
cmp    $0x1,%eax
ja     114b <device_gains+0x2b>
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1030 <read_audio_state@plt>
cvttss2si 0x4(%rsp),%ebp
jmp    116a <device_gains+0x4a>
xor    %ebp,%ebp
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <read_audio_state@plt>
test   %eax,%eax
jne    116a <device_gains+0x4a>
mov    %ebx,%edi
call   1040 <device_channels@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @device_gains(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1 x float]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = and i32 %7, 65535
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 13
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 14
br i1 %13, label %14, label %21
14: ; preds = %11, %1
%15 = load i32, i32* %3
%16 = getelementptr inbounds [1 x float], [1 x float]* %4, i64 0, i64 0
%17 = call i32 @read_audio_state(i32 %15, i32 2, i32 0, float* %16)
store i32 %17, i32* %5
%18 = getelementptr inbounds [1 x float], [1 x float]* %4, i64 0, i64 0
%19 = load float, float* %18
%20 = fptosi float %19 to i32
store i32 %20, i32* %2
br label %31
21: ; preds = %11
%22 = load i32, i32* %3
%23 = getelementptr inbounds [1 x float], [1 x float]* %4, i64 0, i64 0
%24 = call i32 @read_audio_state(i32 %22, i32 0, i32 0, float* %23)
store i32 %24, i32* %5
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 0, i32* %2
br label %31
28: ; preds = %21
%29 = load i32, i32* %3
%30 = call i32 @device_channels(i32 %29)
store i32 %30, i32* %2
br label %31
31: ; preds = %28, %27, %14
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @device_gains(i32 %0) {
%2 = alloca [1 x float]
%3 = bitcast [1 x float]* %2 to i8*
%4 = and i32 %0, 65535
%5 = add nsw i32 %4, -13
%6 = icmp ult i32 %5, 2
%7 = getelementptr inbounds [1 x float], [1 x float]* %2, i64 0, i64 0
br i1 %6, label %8, label %12
8: ; preds = %1
%9 = call i32 @read_audio_state(i32 %0, i32 2, i32 0, float* %7)
%10 = load float, float* %7
%11 = fptosi float %10 to i32
br label %17
12: ; preds = %1
%13 = call i32 @read_audio_state(i32 %0, i32 0, i32 0, float* %7)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @device_channels(i32 %0)
br label %17
17: ; preds = %12, %15, %8
%18 = phi i32 [ %11, %8 ], [ %16, %15 ], [ 0, %12 ]
ret i32 %18
}