#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 PATH_MAX;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int open_sg_device(const char *encl) {
  char dev_sg[PATH_MAX];
  int fd;
  snprintf(dev_sg, PATH_MAX, "/dev/%s", encl);
  fd = open(dev_sg, O_RDWR);
  if (fd < 0)
    perror(dev_sg);
  return fd;
}


x86 assembly (clang, -O0):
<open_sg_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
lea    0xe84(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a9 <open_sg_device+0x79>
mov    -0x28(%rbp),%rdi
call   1050 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_sg_device>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%rcx
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xea2(%rip),%rdx
mov    %rbx,%rdi
call   1030 <snprintf@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     118a <open_sg_device+0x5a>
mov    %r14d,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
call   1050 <perror@plt>
jmp    117e <open_sg_device+0x4e>

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

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