#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 _i2c_get_fd(int);
scalar_t__ close(int);
int /*<<< orphan*/ log_message(char *, char *, int);
bool i2c_close_bus(int busno) {
  int fd = _i2c_get_fd(busno);
  if (fd <= 0) {
    log_message("[ERROR][%d-%d-%d %d:%d:%d] ",
                "i2c_close_bus: the bus number (%d) is out of range or the bus "
                "is not yet open\r\n",
                busno);
    return false;
  }
  return close(fd) == 0;
}


x86 assembly (clang, -O0):
<i2c_close_bus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <_i2c_get_fd@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1172 <i2c_close_bus+0x42>
mov    -0x8(%rbp),%edx
lea    0xea6(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1050 <log_message@plt>
movl   $0x0,-0x4(%rbp)
jmp    1189 <i2c_close_bus+0x59>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2c_close_bus>:
push   %rbx
mov    %edi,%ebx
call   1040 <_i2c_get_fd@plt>
test   %eax,%eax
jle    1150 <i2c_close_bus+0x20>
mov    %eax,%edi
call   1030 <close@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
pop    %rbx
ret
lea    0xea9(%rip),%rdi
lea    0xebe(%rip),%rsi
mov    %ebx,%edx
call   1050 <log_message@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"[ERROR][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [80 x i8] c"i2c_close_bus: the bus number (%d) is out of range or the bus is not yet open\0D\0A\00"
define i32 @i2c_close_bus(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @_i2c_get_fd(i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0), i32 %10)
store i32 0, i32* %2
br label %17
12: ; preds = %1
%13 = load i32, i32* %4
%14 = call i64 @close(i32 %13)
%15 = icmp eq i64 %14, 0
%16 = zext i1 %15 to i32
store i32 %16, i32* %2
br label %17
17: ; preds = %12, %9
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@.str = [28 x i8] c"[ERROR][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [80 x i8] c"i2c_close_bus: the bus number (%d) is out of range or the bus is not yet open\0D\0A\00"
define i32 @i2c_close_bus(i32 %0) {
%2 = tail call i32 @_i2c_get_fd(i32 %0)
%3 = icmp slt i32 %2, 1
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %10
6: ; preds = %1
%7 = tail call i64 @close(i32 %2)
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %6, %4
%11 = phi i32 [ 0, %4 ], [ %9, %6 ]
ret i32 %11
}