#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, char *);
int snprintf(char *, int, char *, ...);
int write(int, char *, int);
int bbb_enableI2Cdevice(int bus, unsigned char address, char *module) {
  int fd = -1;
  static int ret = -1;
  char path[128];
  char ptr[128];
  char *wpath = NULL;
  if (address > 0 && module != NULL) {
    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/new_device",
               bus);
      if ((wpath = bbb_wildCardPath(path)) == NULL) {
        return -1;
      }
      if ((fd = open(wpath, O_WRONLY)) < 0) {
        return -1;
      }
      printf("Enabling I2C device(%d), Address(0x%.2x), module(%s)\n", bus,
             address, module);
      ;
      memset(ptr, 0, sizeof(ptr));
      ret = snprintf(ptr, sizeof(ptr), "%s 0x%.2x", module, address);
      if ((ret = write(fd, ptr, ret)) < 0) {
        ret = -1;
      } else {
        ret = 0;
      }
      close(fd);
    } else {
      ret = 1;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<bbb_enableI2Cdevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movq   $0x0,-0x128(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jle    1340 <bbb_enableI2Cdevice+0x1d0>
cmpq   $0x0,-0x18(%rbp)
je     1340 <bbb_enableI2Cdevice+0x1d0>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%r8d
movzbl -0x9(%rbp),%r9d
mov    $0x80,%esi
lea    0xe1f(%rip),%rdx
lea    0xe25(%rip),%rcx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
call   1090 <bbb_wildCardPath@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    1331 <bbb_enableI2Cdevice+0x1c1>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x80,%esi
lea    0xded(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0xa0(%rbp),%rdi
call   1090 <bbb_wildCardPath@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    1265 <bbb_enableI2Cdevice+0xf5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1349 <bbb_enableI2Cdevice+0x1d9>
mov    -0x128(%rbp),%rdi
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1292 <bbb_enableI2Cdevice+0x122>
movl   $0xffffffff,-0x4(%rbp)
jmp    1349 <bbb_enableI2Cdevice+0x1d9>
mov    -0x8(%rbp),%esi
mov    -0x9(%rbp),%al
mov    -0x18(%rbp),%rcx
lea    0xda6(%rip),%rdi
movzbl %al,%edx
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rcx
movzbl -0x9(%rbp),%r8d
mov    $0x80,%esi
lea    0xda5(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    %eax,0x2d71(%rip)
mov    -0x1c(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    0x2d61(%rip),%edx
call   1030 <write@plt>
mov    %eax,0x2d56(%rip)
cmp    $0x0,%eax
jge    131a <bbb_enableI2Cdevice+0x1aa>
movl   $0xffffffff,0x2d43(%rip)
ff ff ff
jmp    1324 <bbb_enableI2Cdevice+0x1b4>
movl   $0x0,0x2d34(%rip)
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
jmp    133b <bbb_enableI2Cdevice+0x1cb>
movl   $0x1,0x2d1d(%rip)
jmp    1340 <bbb_enableI2Cdevice+0x1d0>
mov    0x2d12(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bbb_enableI2Cdevice>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
test   %esi,%esi
je     12ae <bbb_enableI2Cdevice+0x13e>
mov    %rdx,%r14
test   %rdx,%rdx
je     12ae <bbb_enableI2Cdevice+0x13e>
mov    %esi,%ebx
mov    %edi,%r12d
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe4f(%rip),%rdx
lea    0xe55(%rip),%rcx
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %r12d,%r8d
mov    %ebx,%r9d
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbp,%rdi
call   1090 <bbb_wildCardPath@plt>
test   %rax,%rax
je     11e9 <bbb_enableI2Cdevice+0x79>
movl   $0x1,0x2e74(%rip)
jmp    12ae <bbb_enableI2Cdevice+0x13e>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe20(%rip),%rdx
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbp,%rdi
call   1090 <bbb_wildCardPath@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     12b4 <bbb_enableI2Cdevice+0x144>
mov    0x2da7(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     12b4 <bbb_enableI2Cdevice+0x144>
mov    %eax,%r15d
movzbl %bl,%edx
lea    0xdfd(%rip),%rdi
mov    %r12d,%esi
mov    %r14,%rcx
call   1040 <printf@plt>
lea    0x80(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe0a(%rip),%rdx
mov    %rbp,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %eax,0x2dc8(%rip)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
sar    $0x1f,%eax
mov    %eax,0x2db2(%rip)
mov    %r15d,%edi
call   1070 <close@plt>
mov    0x2da4(%rip),%ebp
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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