#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 PATH_MAX;
int loc_code_device(char const *, char *, int);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int valid_enclosure_device(char *);
int enclosure_dev_name(const char *encl, char *sg, int sg_size) {
  if (!strncmp(encl, "sg", 2) && strlen(encl) < PATH_MAX - 6) {
    strncpy(sg, encl, sg_size);
    return valid_enclosure_device(sg);
  }
  return loc_code_device(encl, sg, sg_size);
}


x86 assembly (clang, -O0):
<enclosure_dev_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    11bf <enclosure_dev_name+0x6f>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x6,%ecx
cmp    %ecx,%eax
jge    11bf <enclosure_dev_name+0x6f>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1060 <valid_enclosure_device@plt>
mov    %eax,-0x4(%rbp)
jmp    11d2 <enclosure_dev_name+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <loc_code_device@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enclosure_dev_name>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe9c(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11a4 <enclosure_dev_name+0x54>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    0x2e6f(%rip),%rcx
mov    (%rcx),%ecx
add    $0xfffffffa,%ecx
cmp    %ecx,%eax
jge    11a4 <enclosure_dev_name+0x54>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <valid_enclosure_device@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <loc_code_device@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"sg\00"
@PATH_MAX = global i32 0
define i32 @enclosure_dev_name(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = call i32 @strncmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%10 = icmp ne i32 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = load i32, i32* @PATH_MAX
%15 = sub nsw i32 %14, 6
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %24
17: ; preds = %11
%18 = load i8*, i8** %6
%19 = load i8*, i8** %5
%20 = load i32, i32* %7
%21 = call i32 @strncpy(i8* %18, i8* %19, i32 %20)
%22 = load i8*, i8** %6
%23 = call i32 @valid_enclosure_device(i8* %22)
store i32 %23, i32* %4
br label %29
24: ; preds = %11, %3
%25 = load i8*, i8** %5
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = call i32 @loc_code_device(i8* %25, i8* %26, i32 %27)
store i32 %28, i32* %4
br label %29
29: ; preds = %24, %17
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@.str = [3 x i8] c"sg\00"
@PATH_MAX = global i32 0
define i32 @enclosure_dev_name(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = load i32, i32* @PATH_MAX
%9 = add nsw i32 %8, -6
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %2)
%13 = tail call i32 @valid_enclosure_device(i8* %1)
br label %16
14: ; preds = %6, %3
%15 = tail call i32 @loc_code_device(i8* %0, i8* %1, i32 %2)
br label %16
16: ; preds = %14, %11
%17 = phi i32 [ %15, %14 ], [ %13, %11 ]
ret i32 %17
}