#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 */
unsigned int I2C_read();
int /*<<< orphan*/ I2C_start();
int /*<<< orphan*/ I2C_stop();
int /*<<< orphan*/ I2C_write(int);
unsigned char DS1307_read(unsigned char addr) {
  unsigned int temp, ret;
  I2C_start();
  I2C_write(0xD0);
  I2C_write(addr);
  I2C_start();
  I2C_write(0XD1);
  ret = I2C_read();
  I2C_stop();
  temp = ret;
  ret = (((ret / 16) * 10) + (temp & 0x0f));
  return ret;
}


x86 assembly (clang, -O0):
<DS1307_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x0,%al
call   1050 <I2C_start@plt>
mov    $0xd0,%edi
call   1060 <I2C_write@plt>
movzbl -0x1(%rbp),%edi
call   1060 <I2C_write@plt>
mov    $0x0,%al
call   1050 <I2C_start@plt>
mov    $0xd1,%edi
call   1060 <I2C_write@plt>
mov    $0x0,%al
call   1040 <I2C_read@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <I2C_stop@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x4,%eax
imul   $0xa,%eax,%eax
mov    -0x8(%rbp),%ecx
and    $0xf,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DS1307_read>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <I2C_start@plt>
mov    $0xd0,%edi
call   1060 <I2C_write@plt>
mov    %ebx,%edi
call   1060 <I2C_write@plt>
xor    %eax,%eax
call   1050 <I2C_start@plt>
mov    $0xd1,%edi
call   1060 <I2C_write@plt>
xor    %eax,%eax
call   1040 <I2C_read@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <I2C_stop@plt>
mov    %ebx,%eax
shr    $0x4,%eax
lea    (%rax,%rax,4),%eax
and    $0xf,%ebx
lea    (%rbx,%rax,2),%eax
pop    %rbx
ret

LLVM IR (-O0):
define zeroext i8 @DS1307_read(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
store i8 %0, i8* %2
%5 = call i32 (...) @I2C_start()
%6 = call i32 @I2C_write(i32 208)
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = call i32 @I2C_write(i32 %8)
%10 = call i32 (...) @I2C_start()
%11 = call i32 @I2C_write(i32 209)
%12 = call i32 (...) @I2C_read()
store i32 %12, i32* %4
%13 = call i32 (...) @I2C_stop()
%14 = load i32, i32* %4
store i32 %14, i32* %3
%15 = load i32, i32* %4
%16 = udiv i32 %15, 16
%17 = mul i32 %16, 10
%18 = load i32, i32* %3
%19 = and i32 %18, 15
%20 = add i32 %17, %19
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = trunc i32 %21 to i8
ret i8 %22
}

LLVM IR (-O2):
define zeroext i8 @DS1307_read(i8 zeroext %0) {
%2 = tail call i32 (...) @I2C_start()
%3 = tail call i32 @I2C_write(i32 208)
%4 = zext i8 %0 to i32
%5 = tail call i32 @I2C_write(i32 %4)
%6 = tail call i32 (...) @I2C_start()
%7 = tail call i32 @I2C_write(i32 209)
%8 = tail call i32 (...) @I2C_read()
%9 = tail call i32 (...) @I2C_stop()
%10 = lshr i32 %8, 4
%11 = mul nuw i32 %10, 10
%12 = and i32 %8, 15
%13 = add nuw i32 %11, %12
%14 = trunc i32 %13 to i8
ret i8 %14
}