#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*/ env_name;

/* Variables and functions */
int /*<<< orphan*/ aeron_env_set(char *, char const *);
int /*<<< orphan*/ aeron_env_unset(char *);
scalar_t__ toupper(char const);
int aeron_properties_setenv(const char *name, const char *value) {
  char env_name[2048];
  for (size_t i = 0; i < sizeof(env_name); i++) {
    const char c = name[i];
    if ('.' == c) {
      env_name[i] = '_';
    } else if ('\0' == c) {
      env_name[i] = c;
      break;
    } else {
      env_name[i] = (char)toupper(c);
    }
  }
  if ('\0' == *value) {
    aeron_env_unset(env_name);
  } else {
    aeron_env_set(env_name, value);
  }
  return 0;
}


x86 assembly (clang, -O0):
<aeron_properties_setenv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x818(%rbp)
cmpq   $0x800,-0x818(%rbp)
jae    1202 <aeron_properties_setenv+0xd2>
mov    -0x8(%rbp),%rax
mov    -0x818(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x819(%rbp)
movsbl -0x819(%rbp),%ecx
mov    $0x2e,%eax
cmp    %ecx,%eax
jne    119b <aeron_properties_setenv+0x6b>
mov    -0x818(%rbp),%rax
movb   $0x5f,-0x810(%rbp,%rax,1)
5f
jmp    11e6 <aeron_properties_setenv+0xb6>
movsbl -0x819(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11c5 <aeron_properties_setenv+0x95>
mov    -0x819(%rbp),%cl
mov    -0x818(%rbp),%rax
mov    %cl,-0x810(%rbp,%rax,1)
jmp    1202 <aeron_properties_setenv+0xd2>
movsbl -0x819(%rbp),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x818(%rbp),%rax
mov    %cl,-0x810(%rbp,%rax,1)
jmp    11e6 <aeron_properties_setenv+0xb6>
jmp    11eb <aeron_properties_setenv+0xbb>
mov    -0x818(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x818(%rbp)
jmp    114e <aeron_properties_setenv+0x1e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1224 <aeron_properties_setenv+0xf4>
lea    -0x810(%rbp),%rdi
call   1050 <aeron_env_unset@plt>
jmp    1234 <aeron_properties_setenv+0x104>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <aeron_env_set@plt>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aeron_properties_setenv>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
jmp    1160 <aeron_properties_setenv+0x30>
cs nopw 0x0(%rax,%rax,1)
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x800,%rbx
je     117e <aeron_properties_setenv+0x4e>
movzbl (%r15,%rbx,1),%ecx
mov    $0x5f,%al
cmp    $0x2e,%cl
je     1150 <aeron_properties_setenv+0x20>
test   %cl,%cl
je     117a <aeron_properties_setenv+0x4a>
movsbl %cl,%edi
call   1040 <toupper@plt>
jmp    1150 <aeron_properties_setenv+0x20>
movb   $0x0,(%rsp,%rbx,1)
cmpb   $0x0,(%r14)
je     1191 <aeron_properties_setenv+0x61>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1030 <aeron_env_set@plt>
jmp    1199 <aeron_properties_setenv+0x69>
mov    %rsp,%rdi
call   1050 <aeron_env_unset@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @aeron_properties_setenv(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [2048 x i8]
%6 = alloca i64
%7 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* %6
br label %8
8: ; preds = %38, %2
%9 = load i64, i64* %6
%10 = icmp ult i64 %9, 2048
br i1 %10, label %11, label %41
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i64, i64* %6
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i8, i8* %14
store i8 %15, i8* %7
%16 = load i8, i8* %7
%17 = sext i8 %16 to i32
%18 = icmp eq i32 46, %17
br i1 %18, label %19, label %22
19: ; preds = %11
%20 = load i64, i64* %6
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %20
store i8 95, i8* %21
br label %37
22: ; preds = %11
%23 = load i8, i8* %7
%24 = sext i8 %23 to i32
%25 = icmp eq i32 0, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i8, i8* %7
%28 = load i64, i64* %6
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %28
store i8 %27, i8* %29
br label %41
30: ; preds = %22
%31 = load i8, i8* %7
%32 = call i64 @toupper(i8 signext %31)
%33 = trunc i64 %32 to i8
%34 = load i64, i64* %6
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 %34
store i8 %33, i8* %35
br label %36
36: ; preds = %30
br label %37
37: ; preds = %36, %19
br label %38
38: ; preds = %37
%39 = load i64, i64* %6
%40 = add i64 %39, 1
store i64 %40, i64* %6
br label %8
41: ; preds = %26, %8
%42 = load i8*, i8** %4
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 0, %44
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%48 = call i32 @aeron_env_unset(i8* %47)
br label %53
49: ; preds = %41
%50 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%51 = load i8*, i8** %4
%52 = call i32 @aeron_env_set(i8* %50, i8* %51)
br label %53
53: ; preds = %49, %46
ret i32 0
}

LLVM IR (-O2):
define i32 @aeron_properties_setenv(i8* nocapture %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %14
%6 = phi i64 [ 0, %2 ], [ %17, %14 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %11 [
i8 46, label %14
i8 0, label %9
]
9: ; preds = %5
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %6
store i8 0, i8* %10
br label %19
11: ; preds = %5
%12 = tail call i64 @toupper(i8 signext %8)
%13 = trunc i64 %12 to i8
br label %14
14: ; preds = %5, %11
%15 = phi i8 [ %13, %11 ], [ 95, %5 ]
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %6
store i8 %15, i8* %16
%17 = add nuw nsw i64 %6, 1
%18 = icmp eq i64 %17, 2048
br i1 %18, label %19, label %5
19: ; preds = %14, %9
%20 = load i8, i8* %1
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @aeron_env_unset(i8* %4)
br label %26
24: ; preds = %19
%25 = call i32 @aeron_env_set(i8* %4, i8* %1)
br label %26
26: ; preds = %24, %22
ret i32 0
}