#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 */
int /*<<< orphan*/ ads_confige(unsigned int);
int /*<<< orphan*/ ads_point_reg();
unsigned short iic_read_m();
int /*<<< orphan*/ iic_write_m(int);
int /*<<< orphan*/ start();
int /*<<< orphan*/ stop();
unsigned int ads_read(unsigned int channel) {
  unsigned short int result = 0;
  if (channel > 4)
    channel = 0;
  ads_confige(channel);
  ads_point_reg();
  start();
  iic_write_m(0x91);
  result |= iic_read_m() << 8;
  result |= iic_read_m();
  stop();
  return result;
}


x86 assembly (clang, -O0):
<ads_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movw   $0x0,-0x6(%rbp)
cmpl   $0x4,-0x4(%rbp)
jbe    1182 <ads_read+0x22>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <ads_confige@plt>
mov    $0x0,%al
call   1080 <ads_point_reg@plt>
mov    $0x0,%al
call   1060 <start@plt>
mov    $0x91,%edi
call   1030 <iic_write_m@plt>
mov    $0x0,%al
call   1070 <iic_read_m@plt>
movzwl %ax,%ecx
shl    $0x8,%ecx
movzwl -0x6(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x6(%rbp)
mov    $0x0,%al
call   1070 <iic_read_m@plt>
movzwl %ax,%ecx
movzwl -0x6(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x6(%rbp)
mov    $0x0,%al
call   1050 <stop@plt>
movzwl -0x6(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ads_read>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
cmp    $0x5,%edi
cmovae %eax,%edi
call   1040 <ads_confige@plt>
xor    %eax,%eax
call   1080 <ads_point_reg@plt>
xor    %eax,%eax
call   1060 <start@plt>
mov    $0x91,%edi
call   1030 <iic_write_m@plt>
xor    %eax,%eax
call   1070 <iic_read_m@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
xor    %eax,%eax
call   1070 <iic_read_m@plt>
mov    %eax,%ebp
or     %ebx,%ebp
xor    %eax,%eax
call   1050 <stop@plt>
movzwl %bp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ads_read(i32 %0) {
%2 = alloca i32
%3 = alloca i16
store i32 %0, i32* %2
store i16 0, i16* %3
%4 = load i32, i32* %2
%5 = icmp ugt i32 %4, 4
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 0, i32* %2
br label %7
7: ; preds = %6, %1
%8 = load i32, i32* %2
%9 = call i32 @ads_confige(i32 %8)
%10 = call i32 (...) @ads_point_reg()
%11 = call i32 (...) @start()
%12 = call i32 @iic_write_m(i32 145)
%13 = call zeroext i16 (...) @iic_read_m()
%14 = zext i16 %13 to i32
%15 = shl i32 %14, 8
%16 = load i16, i16* %3
%17 = zext i16 %16 to i32
%18 = or i32 %17, %15
%19 = trunc i32 %18 to i16
store i16 %19, i16* %3
%20 = call zeroext i16 (...) @iic_read_m()
%21 = zext i16 %20 to i32
%22 = load i16, i16* %3
%23 = zext i16 %22 to i32
%24 = or i32 %23, %21
%25 = trunc i32 %24 to i16
store i16 %25, i16* %3
%26 = call i32 (...) @stop()
%27 = load i16, i16* %3
%28 = zext i16 %27 to i32
ret i32 %28
}

LLVM IR (-O2):
define i32 @ads_read(i32 %0) {
%2 = icmp ugt i32 %0, 4
%3 = select i1 %2, i32 0, i32 %0
%4 = tail call i32 @ads_confige(i32 %3)
%5 = tail call i32 (...) @ads_point_reg()
%6 = tail call i32 (...) @start()
%7 = tail call i32 @iic_write_m(i32 145)
%8 = tail call zeroext i16 (...) @iic_read_m()
%9 = shl i16 %8, 8
%10 = tail call zeroext i16 (...) @iic_read_m()
%11 = or i16 %9, %10
%12 = tail call i32 (...) @stop()
%13 = zext i16 %11 to i32
ret i32 %13
}