#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 *, ...);
int i2c_read_byte(int, int, int *);
int i2c_write_byte(int, int, int);
int /*<<< orphan*/ stdout;
int ds1307_halt(int file, bool halt) {
  int res;
  uint8_t sec;
  if ((res = i2c_read_byte(file, (0x00), &sec)) < 0) {
    return res;
  }
  if (halt) {
    sec |= (1 << 7);
  } else {
    if (false == (sec & (1 << 7))) {
      fprintf(stdout, "Halt bit is already cleared (0x%02x)\n", sec);
      return 0;
    }
    sec &= (~(1 << 7));
  }
  if ((res = i2c_write_byte(file, (0x00), sec)) < 0) {
    return res;
  }
  fprintf(stdout, "Halt bit %s (0x%02x)\n", halt ? "set" : "cleared", sec);
  return 0;
}


x86 assembly (clang, -O0):
<ds1307_halt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
lea    -0x14(%rbp),%rdx
call   1040 <i2c_read_byte@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    1163 <ds1307_halt+0x33>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121e <ds1307_halt+0xee>
cmpl   $0x0,-0xc(%rbp)
je     117d <ds1307_halt+0x4d>
mov    -0x14(%rbp),%eax
or     $0x80,%eax
mov    %eax,-0x14(%rbp)
jmp    11c1 <ds1307_halt+0x91>
mov    -0x14(%rbp),%ecx
and    $0x80,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11b6 <ds1307_halt+0x86>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121e <ds1307_halt+0xee>
mov    -0x14(%rbp),%eax
and    $0xffffff7f,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1050 <i2c_write_byte@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    11e5 <ds1307_halt+0xb5>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121e <ds1307_halt+0xee>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%ecx
lea    0xe48(%rip),%rdx
lea    0xe3d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x14(%rbp),%ecx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds1307_halt>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xc(%rsp),%rdx
xor    %esi,%esi
call   1040 <i2c_read_byte@plt>
test   %eax,%eax
js     11c9 <ds1307_halt+0x99>
mov    0xc(%rsp),%edx
test   %r14d,%r14d
je     115e <ds1307_halt+0x2e>
or     $0x80,%edx
jmp    1184 <ds1307_halt+0x54>
test   $0x80,%dl
jne    117e <ds1307_halt+0x4e>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11cb <ds1307_halt+0x9b>
and    $0xffffff7f,%edx
mov    %edx,0xc(%rsp)
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <i2c_write_byte@plt>
test   %eax,%eax
js     11c9 <ds1307_halt+0x99>
test   %r14d,%r14d
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rax
lea    0xe8b(%rip),%rdx
cmove  %rax,%rdx
mov    0xc(%rsp),%ecx
lea    0xe66(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11cb <ds1307_halt+0x9b>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [38 x i8] c"Halt bit is already cleared (0x%02x)\0A\00"
@.str.1 = [22 x i8] c"Halt bit %s (0x%02x)\0A\00"
@.str.2 = [4 x i8] c"set\00"
@.str.3 = [8 x i8] c"cleared\00"
define i32 @ds1307_halt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = call i32 @i2c_read_byte(i32 %8, i32 0, i32* %7)
store i32 %9, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i32, i32* %6
store i32 %12, i32* %3
br label %45
13: ; preds = %2
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %7
%18 = or i32 %17, 128
store i32 %18, i32* %7
br label %30
19: ; preds = %13
%20 = load i32, i32* %7
%21 = and i32 %20, 128
%22 = icmp eq i32 0, %21
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @stdout
%25 = load i32, i32* %7
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 0, i32* %3
br label %45
27: ; preds = %19
%28 = load i32, i32* %7
%29 = and i32 %28, -129
store i32 %29, i32* %7
br label %30
30: ; preds = %27, %16
%31 = load i32, i32* %4
%32 = load i32, i32* %7
%33 = call i32 @i2c_write_byte(i32 %31, i32 0, i32 %32)
store i32 %33, i32* %6
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = load i32, i32* %6
store i32 %36, i32* %3
br label %45
37: ; preds = %30
%38 = load i32, i32* @stdout
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
%43 = load i32, i32* %7
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %42, i32 %43)
store i32 0, i32* %3
br label %45
45: ; preds = %37, %35, %23, %11
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [38 x i8] c"Halt bit is already cleared (0x%02x)\0A\00"
@.str.1 = [22 x i8] c"Halt bit %s (0x%02x)\0A\00"
@.str.2 = [4 x i8] c"set\00"
@.str.3 = [8 x i8] c"cleared\00"
define i32 @ds1307_halt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @i2c_read_byte(i32 %0, i32 0, i32* %3)
%6 = icmp slt i32 %5, 0
br i1 %6, label %29, label %7
7: ; preds = %2
%8 = icmp eq i32 %1, 0
%9 = load i32, i32* %3
br i1 %8, label %12, label %10
10: ; preds = %7
%11 = or i32 %9, 128
br label %20
12: ; preds = %7
%13 = and i32 %9, 128
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stdout
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %29
18: ; preds = %12
%19 = and i32 %9, -129
br label %20
20: ; preds = %18, %10
%21 = phi i32 [ %19, %18 ], [ %11, %10 ]
store i32 %21, i32* %3
%22 = call i32 @i2c_write_byte(i32 %0, i32 0, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %20
%25 = load i32, i32* @stdout
%26 = select i1 %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%27 = load i32, i32* %3
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27)
br label %29
29: ; preds = %20, %2, %24, %15
%30 = phi i32 [ 0, %24 ], [ 0, %15 ], [ %5, %2 ], [ %22, %20 ]
ret i32 %30
}