#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 /*<<< orphan*/ O_RDWR;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int);
int open_bus(int bus) {
  int file;
  char filename[64];
  snprintf(filename, 64, "%s%d", "/dev/i2c-", bus);
  if ((file = open(filename, O_RDWR)) < 0)
    perror("Failed to open the i2c bus");
  return file;
}


x86 assembly (clang, -O0):
<open_bus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x4(%rbp),%r8d
mov    $0x40,%esi
lea    0xeb1(%rip),%rdx
lea    0xeaf(%rip),%rcx
call   1030 <snprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1185 <open_bus+0x55>
lea    0xe8f(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_bus>:
push   %rbx
sub    $0x40,%rsp
mov    %edi,%r8d
lea    0xec1(%rip),%rdx
lea    0xebf(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
call   1030 <snprintf@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1175 <open_bus+0x45>
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
ret
lea    0xe93(%rip),%rdi
call   1050 <perror@plt>
jmp    116d <open_bus+0x3d>

LLVM IR (-O0):
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [10 x i8] c"/dev/i2c-\00"
@O_RDWR = global i32 0
@.str.2 = [27 x i8] c"Failed to open the i2c bus\00"
define i32 @open_bus(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [64 x i8]
store i32 %0, i32* %2
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* %2
%7 = call i32 @snprintf(i8* %5, i32 64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @O_RDWR
%10 = call i32 @open(i8* %8, i32 %9)
store i32 %10, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load i32, i32* %3
ret i32 %15
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [10 x i8] c"/dev/i2c-\00"
@O_RDWR = global i32 0
@.str.2 = [27 x i8] c"Failed to open the i2c bus\00"
define i32 @open_bus(i32 %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* %3, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
ret i32 %6
}