#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 asprintf(char **, char *, char const *);
int /*<<< orphan*/ die_alloc();
int /*<<< orphan*/ die_errno(char *, char *);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int open_i2c_dev(const char *file) {
  char *path;
  int fd;
  if (asprintf(&path, "/dev/%s", file) < 1)
    die_alloc();
  fd = open(path, O_RDWR);
  if (fd < 0)
    die_errno("opening %s", path);
  free(path);
  return fd;
}


x86 assembly (clang, -O0):
<open_i2c_dev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <asprintf@plt>
cmp    $0x1,%eax
jge    1180 <open_i2c_dev+0x30>
mov    $0x0,%al
call   1040 <die_alloc@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11af <open_i2c_dev+0x5f>
mov    -0x10(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1050 <die_errno@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_i2c_dev>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rdx
lea    0xea1(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1060 <asprintf@plt>
test   %eax,%eax
jg     1174 <open_i2c_dev+0x24>
xor    %eax,%eax
call   1040 <die_alloc@plt>
mov    0x8(%rsp),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    119e <open_i2c_dev+0x4e>
mov    0x8(%rsp),%rsi
lea    0xe6f(%rip),%rdi
call   1050 <die_errno@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/dev/%s\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"opening %s\00"
define i32 @open_i2c_dev(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 (...) @die_alloc()
br label %10
10: ; preds = %8, %1
%11 = load i8*, i8** %3
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i8*, i8** %3
%18 = call i32 @die_errno(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %10
%20 = load i8*, i8** %3
%21 = call i32 @free(i8* %20)
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
@.str = [8 x i8] c"/dev/%s\00"
@O_RDWR = global i32 0
@.str.1 = [11 x i8] c"opening %s\00"
define i32 @open_i2c_dev(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (...) @die_alloc()
br label %8
8: ; preds = %6, %1
%9 = load i8*, i8** %2
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i32 @die_errno(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %8
%17 = load i8*, i8** %2
%18 = call i32 @free(i8* %17)
ret i32 %11
}