#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_RDONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
scalar_t__ sprintf(char *, char const *, int);
int open_analog_device(int pin_number) {
  const char *analog_file_path =
      "/sys/bus/iio/devices/iio\:device0/in_voltage%d_raw";
  int fanalog, a_err = -1;
  char analog_file_buffer[256];
  if (sprintf(analog_file_buffer, analog_file_path, pin_number) < 0) {
    printf("Can't create analog file path\n");
    return a_err;
  }
  fanalog = open(analog_file_buffer, O_RDONLY);
  if (fanalog < 0) {
    printf("Can't open analog device\n");
    return a_err;
  }
  return fanalog;
}


x86 assembly (clang, -O0):
<open_analog_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
lea    0xebb(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0xffffffff,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1050 <sprintf@plt>
cmp    $0x0,%rax
jge    1184 <open_analog_device+0x54>
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c3 <open_analog_device+0x93>
lea    -0x120(%rbp),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11bd <open_analog_device+0x8d>
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c3 <open_analog_device+0x93>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_analog_device>:
sub    $0x108,%rsp
mov    %edi,%edx
lea    0xec0(%rip),%rsi
mov    %rsp,%rdi
call   1050 <sprintf@plt>
test   %rax,%rax
js     116a <open_analog_device+0x3a>
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1040 <open@plt>
test   %eax,%eax
js     1173 <open_analog_device+0x43>
add    $0x108,%rsp
ret
lea    0xeda(%rip),%rdi
jmp    117a <open_analog_device+0x4a>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x108,%rsp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"/sys/bus/iio/devices/iio:device0/in_voltage%d_raw\00"
@.str.1 = [31 x i8] c"Can't create analog file path\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [26 x i8] c"Can't open analog device\0A\00"
define i32 @open_analog_device(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [256 x i8]
store i32 %0, i32* %3
store i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8** %4
store i32 -1, i32* %6
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = load i32, i32* %3
%11 = call i64 @sprintf(i8* %8, i8* %9, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %6
store i32 %15, i32* %2
br label %27
16: ; preds = %1
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* %6
store i32 %24, i32* %2
br label %27
25: ; preds = %16
%26 = load i32, i32* %5
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %22, %13
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [50 x i8] c"/sys/bus/iio/devices/iio:device0/in_voltage%d_raw\00"
@O_RDONLY = global i32 0
@str = [25 x i8] c"Can't open analog device\00"
@str.3 = [30 x i8] c"Can't create analog file path\00"
define i32 @open_analog_device(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i64 @sprintf(i8* %3, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %3, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6, %1
%11 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @str.3, i64 0, i64 0), %1 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0), %6 ]
%12 = call i32 @puts(i8* dereferenceable(1) %11)
br label %13
13: ; preds = %10, %6
%14 = phi i32 [ %8, %6 ], [ -1, %10 ]
ret i32 %14
}