#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 */
short USBSTK5505_I2C_read(int, unsigned char *, int);
short USBSTK5505_I2C_write(int, unsigned char *, int);
int /*<<< orphan*/ USBSTK5505_wait(int);
short AIC3204_rget(unsigned short regnum, unsigned short *regval) {
  short retcode = 0;
  unsigned char cmd[2];
  cmd[0] = regnum & 0x007F;
  cmd[1] = 0;
  retcode |= USBSTK5505_I2C_write(0x18, cmd, 1);
  retcode |= USBSTK5505_I2C_read(0x18, cmd, 1);
  *regval = cmd[0];
  USBSTK5505_wait(10);
  return retcode;
}


x86 assembly (clang, -O0):
<AIC3204_rget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x0,-0x12(%rbp)
movzwl -0x2(%rbp),%eax
and    $0x7f,%eax
mov    %al,-0x14(%rbp)
movb   $0x0,-0x13(%rbp)
lea    -0x14(%rbp),%rsi
mov    $0x18,%edi
mov    $0x1,%edx
call   1030 <USBSTK5505_I2C_write@plt>
movswl %ax,%ecx
movswl -0x12(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x12(%rbp)
lea    -0x14(%rbp),%rsi
mov    $0x18,%edi
mov    $0x1,%edx
call   1050 <USBSTK5505_I2C_read@plt>
movswl %ax,%ecx
movswl -0x12(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x12(%rbp)
movzbl -0x14(%rbp),%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
mov    $0xa,%edi
call   1040 <USBSTK5505_wait@plt>
movswl -0x12(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AIC3204_rget>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
and    $0x7f,%dil
mov    %dil,0xe(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xe(%rsp),%rbx
mov    $0x18,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <USBSTK5505_I2C_write@plt>
mov    %eax,%ebp
mov    $0x18,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <USBSTK5505_I2C_read@plt>
mov    %eax,%ebx
or     %ebp,%ebx
movzbl 0xe(%rsp),%eax
mov    %ax,(%r14)
mov    $0xa,%edi
call   1040 <USBSTK5505_wait@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i16 @AIC3204_rget(i16 zeroext %0, i16* %1) {
%3 = alloca i16
%4 = alloca i16*
%5 = alloca i16
%6 = alloca [2 x i8]
store i16 %0, i16* %3
store i16* %1, i16** %4
store i16 0, i16* %5
%7 = load i16, i16* %3
%8 = zext i16 %7 to i32
%9 = and i32 %8, 127
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 %10, i8* %11
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 0, i8* %12
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%14 = call signext i16 @USBSTK5505_I2C_write(i32 24, i8* %13, i32 1)
%15 = sext i16 %14 to i32
%16 = load i16, i16* %5
%17 = sext i16 %16 to i32
%18 = or i32 %17, %15
%19 = trunc i32 %18 to i16
store i16 %19, i16* %5
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%21 = call signext i16 @USBSTK5505_I2C_read(i32 24, i8* %20, i32 1)
%22 = sext i16 %21 to i32
%23 = load i16, i16* %5
%24 = sext i16 %23 to i32
%25 = or i32 %24, %22
%26 = trunc i32 %25 to i16
store i16 %26, i16* %5
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%28 = load i8, i8* %27
%29 = zext i8 %28 to i16
%30 = load i16*, i16** %4
store i16 %29, i16* %30
%31 = call i32 @USBSTK5505_wait(i32 10)
%32 = load i16, i16* %5
ret i16 %32
}

LLVM IR (-O2):
define signext i16 @AIC3204_rget(i16 zeroext %0, i16* nocapture writeonly %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = trunc i16 %0 to i8
%6 = and i8 %5, 127
store i8 %6, i8* %4
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %7
%8 = call signext i16 @USBSTK5505_I2C_write(i32 24, i8* %4, i32 1)
%9 = call signext i16 @USBSTK5505_I2C_read(i32 24, i8* %4, i32 1)
%10 = or i16 %9, %8
%11 = load i8, i8* %4
%12 = zext i8 %11 to i16
store i16 %12, i16* %1
%13 = call i32 @USBSTK5505_wait(i32 10)
ret i16 %10
}