#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*/ uint8_t;
typedef void uint16_t;

/* Variables and functions */
int /*<<< orphan*/ ltc185x_create_cmd(int /*<<< orphan*/, int /*<<< orphan*/,
                                      int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ltc185x_en();
int /*<<< orphan*/ ltc185x_start_conv();
int ltc185x_xfer(int /*<<< orphan*/ volatile, void *);
int ltc185x_read_ch(uint16_t *data, uint8_t ch, uint8_t range, uint8_t mode,
                    uint8_t polarity) {
  volatile uint8_t cmd;
  ltc185x_en();
  cmd = ltc185x_create_cmd(ch, range, mode, polarity);
  ltc185x_xfer(cmd, (void *)0);
  ltc185x_start_conv();
  return ltc185x_xfer(cmd, data);
}


x86 assembly (clang, -O0):
<ltc185x_read_ch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    $0x0,%al
call   1030 <ltc185x_en@plt>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1050 <ltc185x_create_cmd@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <ltc185x_xfer@plt>
mov    $0x0,%al
call   1060 <ltc185x_start_conv@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <ltc185x_xfer@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltc185x_read_ch>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%r14d
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <ltc185x_en@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1050 <ltc185x_create_cmd@plt>
mov    %eax,0xc(%rsp)
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1040 <ltc185x_xfer@plt>
xor    %eax,%eax
call   1060 <ltc185x_start_conv@plt>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <ltc185x_xfer@plt>

LLVM IR (-O0):
define i32 @ltc185x_read_ch(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = call i32 (...) @ltc185x_en()
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = load i32, i32* %9
%16 = load i32, i32* %10
%17 = call i32 @ltc185x_create_cmd(i32 %13, i32 %14, i32 %15, i32 %16)
store volatile i32 %17, i32* %11
%18 = load volatile i32, i32* %11
%19 = call i32 @ltc185x_xfer(i32 %18, i8* null)
%20 = call i32 (...) @ltc185x_start_conv()
%21 = load volatile i32, i32* %11
%22 = load i8*, i8** %6
%23 = call i32 @ltc185x_xfer(i32 %21, i8* %22)
ret i32 %23
}

LLVM IR (-O2):
define i32 @ltc185x_read_ch(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = tail call i32 (...) @ltc185x_en()
%9 = tail call i32 @ltc185x_create_cmd(i32 %1, i32 %2, i32 %3, i32 %4)
store volatile i32 %9, i32* %6
%10 = load volatile i32, i32* %6
%11 = tail call i32 @ltc185x_xfer(i32 %10, i8* null)
%12 = tail call i32 (...) @ltc185x_start_conv()
%13 = load volatile i32, i32* %6
%14 = tail call i32 @ltc185x_xfer(i32 %13, i8* %0)
ret i32 %14
}