#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 */
char *getenv(char *);
int /*<<< orphan*/ setenv(char *, char *, int /*<<< orphan*/);
int athame_is_set(char *env, int def) {
  char *env_val = getenv(env);
  if (!env_val) {
    setenv(env, def ? "1" : "0", 0);
    return def;
  } else {
    return env_val[0] == '1';
  }
}


x86 assembly (clang, -O0):
<athame_is_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1175 <athame_is_set+0x55>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%ecx
lea    0xead(%rip),%rsi
lea    0xea4(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
xor    %edx,%edx
call   1040 <setenv@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118a <athame_is_set+0x6a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x31,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<athame_is_set>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
call   1030 <getenv@plt>
test   %rax,%rax
je     113d <athame_is_set+0x1d>
xor    %ebx,%ebx
cmpb   $0x31,(%rax)
sete   %bl
jmp    115b <athame_is_set+0x3b>
test   %ebx,%ebx
lea    0xebc(%rip),%rax
lea    0xeb3(%rip),%rsi
cmove  %rax,%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1040 <setenv@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i32 @athame_is_set(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i8* @getenv(i8* %7)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %19, label %11
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%17 = call i32 @setenv(i8* %12, i8* %16, i32 0)
%18 = load i32, i32* %5
store i32 %18, i32* %3
br label %26
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 49
%25 = zext i1 %24 to i32
store i32 %25, i32* %3
br label %26
26: ; preds = %19, %11
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i32 @athame_is_set(i8* %0, i32 %1) {
%3 = tail call i8* @getenv(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = icmp eq i32 %1, 0
%7 = select i1 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%8 = tail call i32 @setenv(i8* %0, i8* %7, i32 0)
br label %13
9: ; preds = %2
%10 = load i8, i8* %3
%11 = icmp eq i8 %10, 49
%12 = zext i1 %11 to i32
br label %13
13: ; preds = %9, %5
%14 = phi i32 [ %12, %9 ], [ %1, %5 ]
ret i32 %14
}