#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*/ I2C_Start();
int /*<<< orphan*/ I2C_Stop();
int /*<<< orphan*/ I2C_Wr(char);
ds1307_set_controlreg(char out, char sqwe, char rs) {
  char rsw = rs;
  if (rs > 3 || rs < 0)
    rsw = 0;
  char sqwew = (sqwe & 0x01) * 0x10;
  char outw = (out & 0x01) * 0x80;
  char writereg = outw + sqwew + rsw;
  I2C_Start();
  I2C_Wr(0xD0);
  I2C_Wr(0x07);
  I2C_Wr(writereg);
  I2C_Stop();
}


x86 assembly (clang, -O0):
<ds1307_set_controlreg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %dil,%dl
mov    %dl,-0x5(%rbp)
mov    %cl,-0x6(%rbp)
mov    %al,-0x7(%rbp)
mov    -0x7(%rbp),%al
mov    %al,-0x8(%rbp)
movsbl -0x7(%rbp),%eax
cmp    $0x3,%eax
jg     1169 <ds1307_set_controlreg+0x39>
movsbl -0x7(%rbp),%eax
cmp    $0x0,%eax
jge    116d <ds1307_set_controlreg+0x3d>
movb   $0x0,-0x8(%rbp)
movsbl -0x6(%rbp),%eax
and    $0x1,%eax
shl    $0x4,%eax
mov    %al,-0x9(%rbp)
movsbl -0x5(%rbp),%eax
and    $0x1,%eax
shl    $0x7,%eax
mov    %al,-0xa(%rbp)
movsbl -0xa(%rbp),%eax
movsbl -0x9(%rbp),%ecx
add    %ecx,%eax
movsbl -0x8(%rbp),%ecx
add    %ecx,%eax
mov    %al,-0xb(%rbp)
mov    $0x0,%al
call   1040 <I2C_Start@plt>
mov    $0xffffffd0,%edi
call   1030 <I2C_Wr@plt>
mov    $0x7,%edi
call   1030 <I2C_Wr@plt>
movsbl -0xb(%rbp),%edi
call   1030 <I2C_Wr@plt>
mov    $0x0,%al
call   1050 <I2C_Stop@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds1307_set_controlreg>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
cmp    $0x4,%dl
cmovae %eax,%edx
shl    $0x4,%sil
and    $0x10,%sil
shl    $0x7,%bl
or     %sil,%bl
add    %dl,%bl
xor    %eax,%eax
call   1040 <I2C_Start@plt>
mov    $0xffffffd0,%edi
call   1030 <I2C_Wr@plt>
mov    $0x7,%edi
call   1030 <I2C_Wr@plt>
movsbl %bl,%edi
call   1030 <I2C_Wr@plt>
xor    %eax,%eax
pop    %rbx
jmp    1050 <I2C_Stop@plt>

LLVM IR (-O0):
define i32 @ds1307_set_controlreg(i8 signext %0, i8 signext %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
store i8 %0, i8* %5
store i8 %1, i8* %6
store i8 %2, i8* %7
%12 = load i8, i8* %7
store i8 %12, i8* %8
%13 = load i8, i8* %7
%14 = sext i8 %13 to i32
%15 = icmp sgt i32 %14, 3
br i1 %15, label %20, label %16
16: ; preds = %3
%17 = load i8, i8* %7
%18 = sext i8 %17 to i32
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16, %3
store i8 0, i8* %8
br label %21
21: ; preds = %20, %16
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = and i32 %23, 1
%25 = mul nsw i32 %24, 16
%26 = trunc i32 %25 to i8
store i8 %26, i8* %9
%27 = load i8, i8* %5
%28 = sext i8 %27 to i32
%29 = and i32 %28, 1
%30 = mul nsw i32 %29, 128
%31 = trunc i32 %30 to i8
store i8 %31, i8* %10
%32 = load i8, i8* %10
%33 = sext i8 %32 to i32
%34 = load i8, i8* %9
%35 = sext i8 %34 to i32
%36 = add nsw i32 %33, %35
%37 = load i8, i8* %8
%38 = sext i8 %37 to i32
%39 = add nsw i32 %36, %38
%40 = trunc i32 %39 to i8
store i8 %40, i8* %11
%41 = call i32 (...) @I2C_Start()
%42 = call i32 @I2C_Wr(i8 signext -48)
%43 = call i32 @I2C_Wr(i8 signext 7)
%44 = load i8, i8* %11
%45 = call i32 @I2C_Wr(i8 signext %44)
%46 = call i32 (...) @I2C_Stop()
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
define i32 @ds1307_set_controlreg(i8 signext %0, i8 signext %1, i8 signext %2) {
%4 = icmp ugt i8 %2, 3
%5 = select i1 %4, i8 0, i8 %2
%6 = shl i8 %1, 4
%7 = and i8 %6, 16
%8 = shl i8 %0, 7
%9 = or i8 %7, %8
%10 = add i8 %9, %5
%11 = tail call i32 (...) @I2C_Start()
%12 = tail call i32 @I2C_Wr(i8 signext -48)
%13 = tail call i32 @I2C_Wr(i8 signext 7)
%14 = tail call i32 @I2C_Wr(i8 signext %10)
%15 = tail call i32 (...) @I2C_Stop()
ret i32 undef
}