#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 EINVAL;
int /*<<< orphan*/ ds1307_get_sqw(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int i2c_write_byte(int, int, int const);
int /*<<< orphan*/ stderr;
int ds1307_set_sqw(int file, int hz) {
  int res;
  const uint8_t reg_table[] = {(0x00),
                               (0x00 | (1 << 7)),
                               (0x00 | (1 << 4)),
                               (0x00 | (1 << 4) | (1 << 0)),
                               (0x00 | (1 << 4) | (1 << 1)),
                               (0x00 | (1 << 4) | (1 << 0) | (1 << 1))};
  if ((hz < 0) || (hz > 5)) {
    fprintf(stderr, "Invalid sqaure wave setting number `%d'!\n", hz);
    return -EINVAL;
  }
  if ((res = i2c_write_byte(file, (0x07), reg_table[hz])) < 0) {
    return res;
  }
  ds1307_get_sqw(file);
  return 0;
}


x86 assembly (clang, -O0):
<ds1307_set_sqw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb8(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb5(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1173 <ds1307_set_sqw+0x43>
cmpl   $0x5,-0xc(%rbp)
jle    119e <ds1307_set_sqw+0x6e>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe92(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    0x2e44(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d9 <ds1307_set_sqw+0xa9>
mov    -0x8(%rbp),%edi
movslq -0xc(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
mov    $0x7,%esi
call   1050 <i2c_write_byte@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11ca <ds1307_set_sqw+0x9a>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d9 <ds1307_set_sqw+0xa9>
mov    -0x8(%rbp),%edi
call   1040 <ds1307_get_sqw@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds1307_set_sqw>:
push   %rbx
mov    %esi,%edx
cmp    $0x6,%esi
jb     115a <ds1307_set_sqw+0x2a>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xed0(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e84(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
ret
mov    %edi,%ebx
mov    %edx,%eax
lea    0xe9b(%rip),%rcx
mov    (%rcx,%rax,4),%edx
mov    $0x7,%esi
call   1050 <i2c_write_byte@plt>
test   %eax,%eax
js     117f <ds1307_set_sqw+0x4f>
mov    %ebx,%edi
call   1040 <ds1307_get_sqw@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.ds1307_set_sqw.reg_table = [6 x i32] [i32 0, i32 128, i32 16, i32 17, i32 18, i32 19]
@stderr = global i32 0
@.str = [42 x i8] c"Invalid sqaure wave setting number `%d'!\0A\00"
@EINVAL = global i32 0
define i32 @ds1307_set_sqw(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [6 x i32]
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = bitcast [6 x i32]* %7 to i8*
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 5
br i1 %13, label %14, label %20
14: ; preds = %11, %2
%15 = load i32, i32* @stderr
%16 = load i32, i32* %5
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @EINVAL
%19 = sub nsw i32 0, %18
store i32 %19, i32* %3
br label %33
20: ; preds = %11
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = call i32 @i2c_write_byte(i32 %21, i32 7, i32 %25)
store i32 %26, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = load i32, i32* %6
store i32 %29, i32* %3
br label %33
30: ; preds = %20
%31 = load i32, i32* %4
%32 = call i32 @ds1307_get_sqw(i32 %31)
store i32 0, i32* %3
br label %33
33: ; preds = %30, %28, %14
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@__const.ds1307_set_sqw.reg_table = [6 x i32] [i32 0, i32 128, i32 16, i32 17, i32 18, i32 19]
@stderr = global i32 0
@.str = [42 x i8] c"Invalid sqaure wave setting number `%d'!\0A\00"
@EINVAL = global i32 0
define i32 @ds1307_set_sqw(i32 %0, i32 %1) {
%3 = icmp ugt i32 %1, 5
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = load i32, i32* @EINVAL
%8 = sub nsw i32 0, %7
br label %17
9: ; preds = %2
%10 = zext i32 %1 to i64
%11 = getelementptr inbounds [6 x i32], [6 x i32]* @__const.ds1307_set_sqw.reg_table, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 @i2c_write_byte(i32 %0, i32 7, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = tail call i32 @ds1307_get_sqw(i32 %0)
br label %17
17: ; preds = %9, %15, %4
%18 = phi i32 [ %8, %4 ], [ 0, %15 ], [ %13, %9 ]
ret i32 %18
}