#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;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int i2c_read_byte(int, int, int *);
int /*<<< orphan*/ stdout;
int ds1307_get_sqw(int file) {
  int res;
  uint8_t reg;
  const char *freq[] = {"1", "4096", "8192", "32768"};
  if ((res = i2c_read_byte(file, (0x07), &reg)) < 0) {
    return res;
  }
  if (reg & (1 << 4)) {
    int i = reg & ((1 << 1) | (1 << 0));
    fprintf(stdout, "Square wave output is %sHz\n", freq[i]);
  } else {
    fprintf(stdout, "Square wave output is constantly %s\n",
            (reg & (1 << 7)) ? "HIGH" : "LOW");
  }
  return 0;
}


x86 assembly (clang, -O0):
<ds1307_get_sqw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2cbe(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cbb(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2cb8(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cb5(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x7,%esi
lea    -0x10(%rbp),%rdx
call   1040 <i2c_read_byte@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    117f <ds1307_get_sqw+0x5f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f4 <ds1307_get_sqw+0xd4>
mov    -0x10(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     11ba <ds1307_get_sqw+0x9a>
mov    -0x10(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x34(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdx
lea    0xe62(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11ed <ds1307_get_sqw+0xcd>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%ecx
and    $0x80,%ecx
lea    0xe85(%rip),%rdx
lea    0xe79(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe46(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds1307_get_sqw>:
push   %rax
lea    0x4(%rsp),%rdx
mov    $0x7,%esi
call   1040 <i2c_read_byte@plt>
test   %eax,%eax
js     118a <ds1307_get_sqw+0x6a>
mov    0x4(%rsp),%eax
test   $0x10,%al
jne    1162 <ds1307_get_sqw+0x42>
mov    0x2e9d(%rip),%rcx
mov    (%rcx),%edi
test   $0x80,%al
lea    0xf0a(%rip),%rax
lea    0xefe(%rip),%rdx
cmove  %rax,%rdx
lea    0xece(%rip),%rsi
jmp    1183 <ds1307_get_sqw+0x63>
and    $0x3,%eax
mov    0x2e74(%rip),%rcx
mov    (%rcx),%edi
lea    0xee7(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
lea    0xe8f(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
@.str.1 = [5 x i8] c"4096\00"
@.str.2 = [5 x i8] c"8192\00"
@.str.3 = [6 x i8] c"32768\00"
@__const.ds1307_get_sqw.freq = [4 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0)]
@stdout = global i32 0
@.str.4 = [28 x i8] c"Square wave output is %sHz\0A\00"
@.str.5 = [37 x i8] c"Square wave output is constantly %s\0A\00"
@.str.6 = [5 x i8] c"HIGH\00"
@.str.7 = [4 x i8] c"LOW\00"
define i32 @ds1307_get_sqw(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i8*]
%7 = alloca i32
store i32 %0, i32* %3
%8 = bitcast [4 x i8*]* %6 to i8*
%9 = load i32, i32* %3
%10 = call i32 @i2c_read_byte(i32 %9, i32 7, i32* %5)
store i32 %10, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i32, i32* %4
store i32 %13, i32* %2
br label %36
14: ; preds = %1
%15 = load i32, i32* %5
%16 = and i32 %15, 16
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32, i32* %5
%20 = and i32 %19, 3
store i32 %20, i32* %7
%21 = load i32, i32* @stdout
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br label %35
27: ; preds = %14
%28 = load i32, i32* @stdout
%29 = load i32, i32* %5
%30 = and i32 %29, 128
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0)
%34 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %27, %18
store i32 0, i32* %2
br label %36
36: ; preds = %35, %12
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [5 x i8] c"4096\00"
@.str.2 = [5 x i8] c"8192\00"
@.str.3 = [6 x i8] c"32768\00"
@reltable.ds1307_get_sqw = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.ds1307_get_sqw to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.ds1307_get_sqw to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.ds1307_get_sqw to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.ds1307_get_sqw to i64)) to i32)]
@stdout = global i32 0
@.str.4 = [28 x i8] c"Square wave output is %sHz\0A\00"
@.str.5 = [37 x i8] c"Square wave output is constantly %s\0A\00"
@.str.6 = [5 x i8] c"HIGH\00"
@.str.7 = [4 x i8] c"LOW\00"
define i32 @ds1307_get_sqw(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @i2c_read_byte(i32 %0, i32 7, i32* %2)
%5 = icmp slt i32 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %1
%7 = load i32, i32* %2
%8 = and i32 %7, 16
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %6
%11 = and i32 %7, 3
%12 = load i32, i32* @stdout
%13 = zext i32 %11 to i64
%14 = shl i64 %13, 2
%15 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.ds1307_get_sqw to i8*), i64 %14)
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %15)
br label %23
17: ; preds = %6
%18 = load i32, i32* @stdout
%19 = and i32 %7, 128
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0)
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %10, %17, %1
%24 = phi i32 [ %4, %1 ], [ 0, %17 ], [ 0, %10 ]
ret i32 %24
}