#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 */
typedef int /*<<< orphan*/ var;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int nvram_set(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strstr(char const *, char *);
int do_set(const char *pair) {
  char *val = strstr(pair, "=");
  char var[strlen(pair)];
  int stat = 1;
  if (val != NULL) {
    memset(var, 0, sizeof(var));
    strncpy(var, pair, (int)(val - pair));
    stat = nvram_set(var, (char *)(val + 1));
  }
  return stat;
}


x86 assembly (clang, -O0):
<do_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f3 <do_set+0xa3>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
call   1040 <nvram_set@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_set>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
test   %r15,%r15
je     11b8 <do_set+0x68>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1070 <memset@plt>
mov    %r15d,%edx
sub    %r14d,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
add    $0x1,%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <nvram_set@plt>
jmp    11bd <do_set+0x6d>
mov    $0x1,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"=\00"
define i32 @do_set(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @strstr(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %3
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i8, i64 %11
store i64 %11, i64* %5
store i32 1, i32* %6
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %30
16: ; preds = %1
%17 = trunc i64 %11 to i32
%18 = call i32 @memset(i8* %13, i32 0, i32 %17)
%19 = load i8*, i8** %2
%20 = load i8*, i8** %3
%21 = load i8*, i8** %2
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
%26 = call i32 @strncpy(i8* %13, i8* %19, i32 %25)
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = call i32 @nvram_set(i8* %13, i8* %28)
store i32 %29, i32* %6
br label %30
30: ; preds = %16, %1
%31 = load i32, i32* %6
%32 = load i8*, i8** %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @do_set(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 61)
%3 = tail call i32 @strlen(i8* %0)
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp eq i8* %2, null
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = call i32 @memset(i8* %5, i32 0, i32 %3)
%9 = ptrtoint i8* %2 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = call i32 @strncpy(i8* %5, i8* %0, i32 %12)
%14 = getelementptr inbounds i8, i8* %2, i64 1
%15 = call i32 @nvram_set(i8* %5, i8* %14)
br label %16
16: ; preds = %7, %1
%17 = phi i32 [ %15, %7 ], [ 1, %1 ]
ret i32 %17
}