#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 uint8_t;
typedef unsigned int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int read(int, int *, int);
int write(int, char *, int);
unsigned int PROM_read(int DA, char PROM_CMD) {
  uint16_t ret = 0;
  uint8_t r8b[] = {0, 0};
  if (write(DA, &PROM_CMD, 1) != 1) {
    printf("read set reg Failed to write to the i2c bus.\n");
  }
  if (read(DA, r8b, 2) != 2) {
    printf("Failed to read from the i2c bus.\n");
  }
  ret = r8b[0] * 256 + r8b[1];
  return ret;
}


x86 assembly (clang, -O0):
<PROM_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     118e <PROM_read+0x4e>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
cmp    $0x2,%eax
je     11b4 <PROM_read+0x74>
lea    0xe7f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PROM_read>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %sil,0x7(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     1165 <PROM_read+0x35>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1050 <read@plt>
cmp    $0x2,%eax
je     1187 <PROM_read+0x57>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%eax
shl    $0x8,%eax
add    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [46 x i8] c"read set reg Failed to write to the i2c bus.\0A\00"
@.str.1 = [34 x i8] c"Failed to read from the i2c bus.\0A\00"
define i32 @PROM_read(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca [2 x i32]
store i32 %0, i32* %3
store i8 %1, i8* %4
store i32 0, i32* %5
%7 = bitcast [2 x i32]* %6 to i8*
%8 = load i32, i32* %3
%9 = call i32 @write(i32 %8, i8* %4, i32 1)
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* %3
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%16 = call i32 @read(i32 %14, i32* %15, i32 2)
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%22 = load i32, i32* %21
%23 = mul nsw i32 %22, 256
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%25 = load i32, i32* %24
%26 = add nsw i32 %23, %25
store i32 %26, i32* %5
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
@str = [33 x i8] c"Failed to read from the i2c bus.\00"
@str.2 = [45 x i8] c"read set reg Failed to write to the i2c bus.\00"
define i32 @PROM_read(i32 %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca i64
store i8 %1, i8* %3
%5 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%6 = call i32 @write(i32 %0, i8* %3, i32 1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = bitcast i64* %4 to i32*
%12 = call i32 @read(i32 %0, i32* %11, i32 2)
%13 = icmp eq i32 %12, 2
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = bitcast i64* %4 to [2 x i32]*
%18 = load i32, i32* %11
%19 = shl nsw i32 %18, 8
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %17, i64 0, i64 1
%21 = load i32, i32* %20
%22 = add nsw i32 %19, %21
ret i32 %22
}