#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*/ free(char *);
char *nvram_safe_get(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strstr(char *, char *);
char *sub_replace(char *, char *, char *);
int get_sysname_from_nvram(char *sysname) {
  char *name_get = NULL;
  char *str = NULL;
  name_get = nvram_safe_get("hostname");
  if (strlen(name_get) <= 0) {
    printf("Get system name from nvram error!\n");
    return -1;
  }
  strcpy(sysname, name_get);
  if (strstr(sysname, "\"")) {
    str = sub_replace(sysname, "\"", "&#34;");
    strcpy(sysname, str);
    free(str);
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_sysname_from_nvram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe6d(%rip),%rdi
call   1070 <nvram_safe_get@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jg     11c7 <get_sysname_from_nvram+0x57>
lea    0xe53(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1226 <get_sysname_from_nvram+0xb6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     121f <get_sysname_from_nvram+0xaf>
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
lea    0xe2e(%rip),%rdx
call   1080 <sub_replace@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sysname_from_nvram>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xe82(%rip),%rdi
call   1070 <nvram_safe_get@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <strlen@plt>
test   %rax,%rax
jle    11e3 <get_sysname_from_nvram+0x73>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
lea    0xe64(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strstr@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11f5 <get_sysname_from_nvram+0x85>
lea    0xe4d(%rip),%rsi
lea    0xe48(%rip),%rdx
mov    %rbx,%rdi
call   1080 <sub_replace@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    11f5 <get_sysname_from_nvram+0x85>
lea    0xe27(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"hostname\00"
@.str.1 = [35 x i8] c"Get system name from nvram error!\0A\00"
@.str.2 = [2 x i8] c"\22\00"
@.str.3 = [6 x i8] c"&;\00"
define i32 @get_sysname_from_nvram(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %4
store i8* null, i8** %5
%6 = call i8* @nvram_safe_get(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = icmp sle i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %28
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = load i8*, i8** %4
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = load i8*, i8** %3
%17 = call i64 @strstr(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = call i8* @sub_replace(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i8* %21, i8** %5
%22 = load i8*, i8** %3
%23 = load i8*, i8** %5
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %5
%26 = call i32 @free(i8* %25)
br label %27
27: ; preds = %19, %12
store i32 0, i32* %2
br label %28
28: ; preds = %27, %10
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [9 x i8] c"hostname\00"
@.str.2 = [2 x i8] c"\22\00"
@.str.3 = [6 x i8] c"&;\00"
@str = [34 x i8] c"Get system name from nvram error!\00"
define i32 @get_sysname_from_nvram(i8* %0) {
%2 = tail call i8* @nvram_safe_get(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%4 = icmp slt i64 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %15
7: ; preds = %1
%8 = tail call i32 @strcpy(i8* %0, i8* %2)
%9 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = tail call i8* @sub_replace(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @strcpy(i8* %0, i8* %12)
%14 = tail call i32 @free(i8* %12)
br label %15
15: ; preds = %7, %11, %5
%16 = phi i32 [ -1, %5 ], [ 0, %11 ], [ 0, %7 ]
ret i32 %16
}