#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 unsigned long uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned long **, int);
int /*<<< orphan*/ usleep(int);
int write(int, char *, int);
long CONV_read(int DA, char CONV_CMD) {
  long ret = 0;
  uint8_t D[] = {0, 0, 0};
  int h;
  char zero = 0x0;
  if (write(DA, &CONV_CMD, 1) != 1) {
    printf("write reg 8 bit Failed to write to the i2c bus.\n");
  }
  usleep(10000);
  if (write(DA, &zero, 1) != 1) {
    printf("write reset 8 bit Failed to write to the i2c bus.\n");
  }
  h = read(DA, &D, 3);
  if (h != 3) {
    printf("Failed to read from the i2c bus %d.\n", h);
  }
  ret = D[0] * (unsigned long)65536 + D[1] * (unsigned long)256 + D[2];
  return ret;
}


x86 assembly (clang, -O0):
<CONV_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
movb   $0x0,-0x35(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11a5 <CONV_read+0x55>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2710,%edi
call   1070 <usleep@plt>
mov    -0x4(%rbp),%edi
lea    -0x35(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11d7 <CONV_read+0x87>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x3,%edx
call   1060 <read@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x3,-0x34(%rbp)
je     1206 <CONV_read+0xb6>
mov    -0x34(%rbp),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
shl    $0x10,%rax
mov    -0x28(%rbp),%rcx
shl    $0x8,%rcx
add    %rcx,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CONV_read>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
mov    %sil,0xf(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
movb   $0x0,0xe(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     1192 <CONV_read+0x42>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2710,%edi
call   1070 <usleep@plt>
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     11be <CONV_read+0x6e>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1060 <read@plt>
cmp    $0x3,%eax
je     11e4 <CONV_read+0x94>
lea    0xe25(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%rcx
mov    0x18(%rsp),%rax
shl    $0x10,%rcx
shl    $0x8,%rax
add    %rcx,%rax
add    0x20(%rsp),%rax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [49 x i8] c"write reg 8 bit Failed to write to the i2c bus.\0A\00"
@.str.1 = [51 x i8] c"write reset 8 bit Failed to write to the i2c bus.\0A\00"
@.str.2 = [37 x i8] c"Failed to read from the i2c bus %d.\0A\00"
define i64 @CONV_read(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i64
%6 = alloca [3 x i64]
%7 = alloca i32
%8 = alloca i8
store i32 %0, i32* %3
store i8 %1, i8* %4
store i64 0, i64* %5
%9 = bitcast [3 x i64]* %6 to i8*
store i8 0, i8* %8
%10 = load i32, i32* %3
%11 = call i32 @write(i32 %10, i8* %4, i32 1)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = call i32 @usleep(i32 10000)
%17 = load i32, i32* %3
%18 = call i32 @write(i32 %17, i8* %8, i32 1)
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = load i32, i32* %3
%24 = bitcast [3 x i64]* %6 to i64**
%25 = call i32 @read(i32 %23, i64** %24, i32 3)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 3
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load i32, i32* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %28, %22
%32 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 0
%33 = load i64, i64* %32
%34 = mul i64 %33, 65536
%35 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 1
%36 = load i64, i64* %35
%37 = mul i64 %36, 256
%38 = add i64 %34, %37
%39 = getelementptr inbounds [3 x i64], [3 x i64]* %6, i64 0, i64 2
%40 = load i64, i64* %39
%41 = add i64 %38, %40
store i64 %41, i64* %5
%42 = load i64, i64* %5
ret i64 %42
}

LLVM IR (-O2):
@.str.2 = [37 x i8] c"Failed to read from the i2c bus %d.\0A\00"
@str = [50 x i8] c"write reset 8 bit Failed to write to the i2c bus.\00"
@str.3 = [48 x i8] c"write reg 8 bit Failed to write to the i2c bus.\00"
define i64 @CONV_read(i32 %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca [3 x i64]
%5 = alloca i8
store i8 %1, i8* %3
%6 = bitcast [3 x i64]* %4 to i8*
store i8 0, i8* %5
%7 = call i32 @write(i32 %0, i8* %3, i32 1)
%8 = icmp eq i32 %7, 1
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.3, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = tail call i32 @usleep(i32 10000)
%13 = call i32 @write(i32 %0, i8* %5, i32 1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = bitcast [3 x i64]* %4 to i64**
%19 = call i32 @read(i32 %0, i64** %18, i32 3)
%20 = icmp eq i32 %19, 3
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %23
23: ; preds = %21, %17
%24 = getelementptr inbounds [3 x i64], [3 x i64]* %4, i64 0, i64 0
%25 = load i64, i64* %24
%26 = shl i64 %25, 16
%27 = getelementptr inbounds [3 x i64], [3 x i64]* %4, i64 0, i64 1
%28 = load i64, i64* %27
%29 = shl i64 %28, 8
%30 = add i64 %29, %26
%31 = getelementptr inbounds [3 x i64], [3 x i64]* %4, i64 0, i64 2
%32 = load i64, i64* %31
%33 = add i64 %30, %32
ret i64 %33
}