#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*/ LOG_ERR;
int /*<<< orphan*/ _log(int /*<<< orphan*/, char *, ...);
scalar_t__ asprintf(char **, char *, char const *, char const *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
scalar_t__ setenv(char *, char const *, int);
void env_modprobe_options_append(const char *value) {
  const char *old = getenv("MODPROBE_OPTIONS");
  char *env;
  if (old == NULL) {
    setenv("MODPROBE_OPTIONS", value, 1);
    return;
  }
  if (asprintf(&env, "%s %s", old, value) < 0) {
    _log(LOG_ERR, "could not append value to $MODPROBE_OPTIONS\n");
    return;
  }
  if (setenv("MODPROBE_OPTIONS", env, 1) < 0)
    _log(LOG_ERR, "could not setenv(MODPROBE_OPTIONS, \"%s\")\n", env);
  free(env);
}


x86 assembly (clang, -O0):
<env_modprobe_options_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1191 <env_modprobe_options_append+0x41>
mov    -0x8(%rbp),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x1,%edx
call   1060 <setenv@plt>
jmp    1212 <env_modprobe_options_append+0xc2>
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <asprintf@plt>
cmp    $0x0,%rax
jge    11cf <env_modprobe_options_append+0x7f>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1050 <_log@plt>
jmp    1212 <env_modprobe_options_append+0xc2>
mov    -0x18(%rbp),%rsi
lea    0xe26(%rip),%rdi
mov    $0x1,%edx
call   1060 <setenv@plt>
cmp    $0x0,%rax
jge    1209 <env_modprobe_options_append+0xb9>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1050 <_log@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_modprobe_options_append>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c8 <env_modprobe_options_append+0x78>
lea    0xea1(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1070 <asprintf@plt>
test   %rax,%rax
js     11e1 <env_modprobe_options_append+0x91>
mov    0x8(%rsp),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x1,%edx
call   1060 <setenv@plt>
test   %rax,%rax
jns    11bc <env_modprobe_options_append+0x6c>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xe8f(%rip),%rsi
xor    %eax,%eax
call   1050 <_log@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
jmp    11f8 <env_modprobe_options_append+0xa8>
lea    0xe31(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
add    $0x10,%rsp
pop    %rbx
jmp    1060 <setenv@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1050 <_log@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"MODPROBE_OPTIONS\00"
@.str.1 = [6 x i8] c"%s %s\00"
@LOG_ERR = global i32 0
@.str.2 = [45 x i8] c"could not append value to $MODPROBE_OPTIONS\0A\00"
@.str.3 = [42 x i8] c"could not setenv(MODPROBE_OPTIONS, \22%s\22)\0A\00"
define void @env_modprobe_options_append(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i64 @setenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %9, i32 1)
br label %30
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i8*, i8** %2
%14 = call i64 @asprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %12, i8* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @LOG_ERR
%18 = call i32 (i32, i8*, ...) @_log(i32 %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %30
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = call i64 @setenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %20, i32 1)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @LOG_ERR
%25 = load i8*, i8** %4
%26 = call i32 (i32, i8*, ...) @_log(i32 %24, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %23, %19
%28 = load i8*, i8** %4
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %27, %16, %8
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"MODPROBE_OPTIONS\00"
@.str.1 = [6 x i8] c"%s %s\00"
@LOG_ERR = global i32 0
@.str.2 = [45 x i8] c"could not append value to $MODPROBE_OPTIONS\0A\00"
@.str.3 = [42 x i8] c"could not setenv(MODPROBE_OPTIONS, \22%s\22)\0A\00"
define void @env_modprobe_options_append(i8* %0) {
%2 = alloca i8*
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i8** %2 to i8*
%5 = icmp eq i8* %3, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i64 @setenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i32 1)
br label %25
8: ; preds = %1
%9 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @LOG_ERR
%13 = call i32 (i32, i8*, ...) @_log(i32 %12, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %25
14: ; preds = %8
%15 = load i8*, i8** %2
%16 = call i64 @setenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15, i32 1)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* @LOG_ERR
%20 = load i8*, i8** %2
%21 = call i32 (i32, i8*, ...) @_log(i32 %19, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18, %14
%23 = load i8*, i8** %2
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %22, %11, %6
ret void
}