#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 /*<<< orphan*/ ptr;
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
char *bbb_wildCardPath(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, unsigned char);
int snprintf(char *, int, char *, ...);
int write(int, char *, int);
int bbb_disableI2Cdevice(int bus, unsigned char address) {
  int fd = -1;
  static int ret = -1;
  char path[128];
  char ptr[128];
  char *wpath = NULL;
  if (address > 0) {
    memset(path, 0, sizeof(path));
    snprintf(path, sizeof(path), "%s/%d-00%.2x", "/sys/bus/i2c/devices", bus,
             address);
    if ((wpath = bbb_wildCardPath(path)) != NULL) {
      memset(path, 0, sizeof(path));
      snprintf(path, sizeof(path), "/sys/bus/i2c/devices/i2c-%d/delete_device",
               bus);
      if ((wpath = bbb_wildCardPath(path)) != NULL) {
        if ((fd = open(wpath, O_WRONLY)) < 0) {
          return -1;
        }
        printf("Disabling I2C device(%d), Address(0x%.2x)\n", bus, address);
        ;
        memset(ptr, 0, sizeof(ptr));
        ret = snprintf(ptr, sizeof(ptr), "0x%.2x", address);
        if ((ret = write(fd, ptr, ret)) < 0) {
          ret = -1;
        } else {
          ret = 0;
        }
        close(fd);
      }
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<bbb_disableI2Cdevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movq   $0x0,-0x118(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jle    1310 <bbb_disableI2Cdevice+0x1a0>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%r8d
movzbl -0x9(%rbp),%r9d
mov    $0x80,%esi
lea    0xe2e(%rip),%rdx
lea    0xe34(%rip),%rcx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0x90(%rbp),%rdi
call   1090 <bbb_wildCardPath@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
je     130b <bbb_disableI2Cdevice+0x19b>
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x80,%esi
lea    0xdfc(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0x90(%rbp),%rdi
call   1090 <bbb_wildCardPath@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
je     1306 <bbb_disableI2Cdevice+0x196>
mov    -0x118(%rbp),%rdi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    1277 <bbb_disableI2Cdevice+0x107>
movl   $0xffffffff,-0x4(%rbp)
jmp    1319 <bbb_disableI2Cdevice+0x1a9>
mov    -0x8(%rbp),%esi
lea    0xdcb(%rip),%rdi
movzbl -0x9(%rbp),%edx
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rdi
movzbl -0x9(%rbp),%ecx
mov    $0x80,%esi
lea    0xdc3(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    %eax,0x2d97(%rip)
mov    -0x10(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    0x2d87(%rip),%edx
call   1030 <write@plt>
mov    %eax,0x2d7c(%rip)
cmp    $0x0,%eax
jge    12f4 <bbb_disableI2Cdevice+0x184>
movl   $0xffffffff,0x2d69(%rip)
ff ff ff
jmp    12fe <bbb_disableI2Cdevice+0x18e>
movl   $0x0,0x2d5a(%rip)
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
jmp    130b <bbb_disableI2Cdevice+0x19b>
jmp    1310 <bbb_disableI2Cdevice+0x1a0>
mov    0x2d42(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bbb_disableI2Cdevice>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
test   %esi,%esi
je     1285 <bbb_disableI2Cdevice+0x115>
mov    %esi,%ebx
mov    %edi,%r15d
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe5d(%rip),%rdx
lea    0xe63(%rip),%rcx
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %r15d,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbp,%rdi
call   1090 <bbb_wildCardPath@plt>
test   %rax,%rax
je     1285 <bbb_disableI2Cdevice+0x115>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe39(%rip),%rdx
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbp,%rdi
call   1090 <bbb_wildCardPath@plt>
test   %rax,%rax
je     1285 <bbb_disableI2Cdevice+0x115>
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     1299 <bbb_disableI2Cdevice+0x129>
mov    %eax,%r14d
movzbl %bl,%edx
lea    0xe22(%rip),%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe27(%rip),%rdx
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %ebx,%ecx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %eax,0x2df1(%rip)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
sar    $0x1f,%eax
mov    %eax,0x2ddb(%rip)
mov    %r14d,%edi
call   1070 <close@plt>
mov    0x2dcd(%rip),%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%eax
jmp    128b <bbb_disableI2Cdevice+0x11b>

LLVM IR (-O0):
@bbb_disableI2Cdevice.ret = internal global i32 -1
@.str = [13 x i8] c"%s/%d-00%.2x\00"
@.str.1 = [21 x i8] c"/sys/bus/i2c/devices\00"
@.str.2 = [42 x i8] c"/sys/bus/i2c/devices/i2c-%d/delete_device\00"
@O_WRONLY = global i32 0
@.str.3 = [43 x i8] c"Disabling I2C device(%d), Address(0x%.2x)\0A\00"
@.str.4 = [7 x i8] c"0x%.2x\00"
define i32 @bbb_disableI2Cdevice(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca [128 x i8]
%9 = alloca i8*
store i32 %0, i32* %4
store i8 %1, i8* %5
store i32 -1, i32* %6
store i8* null, i8** %9
%10 = load i8, i8* %5
%11 = zext i8 %10 to i32
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %61
13: ; preds = %2
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 128)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %4
%18 = load i8, i8* %5
%19 = zext i8 %18 to i32
%20 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %16, i32 128, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%22 = call i8* @bbb_wildCardPath(i8* %21)
store i8* %22, i8** %9
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %60
24: ; preds = %13
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i32 0, i32 128)
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%28 = load i32, i32* %4
%29 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %27, i32 128, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%31 = call i8* @bbb_wildCardPath(i8* %30)
store i8* %31, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %59
33: ; preds = %24
%34 = load i8*, i8** %9
%35 = load i32, i32* @O_WRONLY
%36 = call i32 @open(i8* %34, i32 %35)
store i32 %36, i32* %6
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 -1, i32* %3
br label %63
39: ; preds = %33
%40 = load i32, i32* %4
%41 = load i8, i8* %5
%42 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %40, i8 zeroext %41)
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%44 = call i32 @memset(i8* %43, i32 0, i32 128)
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%46 = load i8, i8* %5
%47 = zext i8 %46 to i32
%48 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %45, i32 128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %47)
store i32 %48, i32* @bbb_disableI2Cdevice.ret
%49 = load i32, i32* %6
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%51 = load i32, i32* @bbb_disableI2Cdevice.ret
%52 = call i32 @write(i32 %49, i8* %50, i32 %51)
store i32 %52, i32* @bbb_disableI2Cdevice.ret
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %39
store i32 -1, i32* @bbb_disableI2Cdevice.ret
br label %56
55: ; preds = %39
store i32 0, i32* @bbb_disableI2Cdevice.ret
br label %56
56: ; preds = %55, %54
%57 = load i32, i32* %6
%58 = call i32 @close(i32 %57)
br label %59
59: ; preds = %56, %24
br label %60
60: ; preds = %59, %13
br label %61
61: ; preds = %60, %2
%62 = load i32, i32* @bbb_disableI2Cdevice.ret
store i32 %62, i32* %3
br label %63
63: ; preds = %61, %38
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@bbb_disableI2Cdevice.ret = internal unnamed_addr global i32 -1
@.str = [13 x i8] c"%s/%d-00%.2x\00"
@.str.1 = [21 x i8] c"/sys/bus/i2c/devices\00"
@.str.2 = [42 x i8] c"/sys/bus/i2c/devices/i2c-%d/delete_device\00"
@O_WRONLY = global i32 0
@.str.3 = [43 x i8] c"Disabling I2C device(%d), Address(0x%.2x)\0A\00"
@.str.4 = [7 x i8] c"0x%.2x\00"
define i32 @bbb_disableI2Cdevice(i32 %0, i8 zeroext %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = zext i8 %1 to i32
%8 = icmp eq i8 %1, 0
br i1 %8, label %30, label %9
9: ; preds = %2
%10 = call i32 @memset(i8* %5, i32 0, i32 128)
%11 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %5, i32 128, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %7)
%12 = call i8* @bbb_wildCardPath(i8* %5)
%13 = icmp eq i8* %12, null
br i1 %13, label %30, label %14
14: ; preds = %9
%15 = call i32 @memset(i8* %5, i32 0, i32 128)
%16 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %5, i32 128, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%17 = call i8* @bbb_wildCardPath(i8* %5)
%18 = icmp eq i8* %17, null
br i1 %18, label %30, label %19
19: ; preds = %14
%20 = load i32, i32* @O_WRONLY
%21 = call i32 @open(i8* %17, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %19
%24 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %0, i8 zeroext %1)
%25 = call i32 @memset(i8* %6, i32 0, i32 128)
%26 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %7)
store i32 %26, i32* @bbb_disableI2Cdevice.ret
%27 = call i32 @write(i32 %21, i8* %6, i32 %26)
%28 = ashr i32 %27, 31
store i32 %28, i32* @bbb_disableI2Cdevice.ret
%29 = call i32 @close(i32 %21)
br label %30
30: ; preds = %9, %23, %14, %2
%31 = load i32, i32* @bbb_disableI2Cdevice.ret
br label %32
32: ; preds = %19, %30
%33 = phi i32 [ %31, %30 ], [ -1, %19 ]
ret i32 %33
}