#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 const *);
int /*<<< orphan*/ log_fatal(char *, char const *, char *);
int str2int(char *);
int get_env_int(const char *var) {
  char *val;
  int id;
  if (!(val = getenv(var)))
    return (-1);
  if ((id = str2int(val)) < 0)
    log_fatal("Bad environment value: %s=%s\n", var, val);
  return (id);
}


x86 assembly (clang, -O0):
<get_env_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    115f <get_env_int+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <get_env_int+0x5e>
mov    -0x18(%rbp),%rdi
call   1040 <str2int@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1188 <get_env_int+0x58>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe7d(%rip),%rdi
call   1050 <log_fatal@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_env_int>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <getenv@plt>
test   %rax,%rax
je     1166 <get_env_int+0x36>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <str2int@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    116b <get_env_int+0x3b>
lea    0xea7(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <log_fatal@plt>
jmp    116b <get_env_int+0x3b>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Bad environment value: %s=%s\0A\00"
define i32 @get_env_int(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @getenv(i8* %6)
store i8* %7, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 -1, i32* %2
br label %20
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i32 @str2int(i8* %11)
store i32 %12, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i32 @log_fatal(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16)
br label %18
18: ; preds = %14, %10
%19 = load i32, i32* %5
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %9
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [30 x i8] c"Bad environment value: %s=%s\0A\00"
define i32 @get_env_int(i8* %0) {
%2 = tail call i8* @getenv(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i32 @str2int(i8* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @log_fatal(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %2)
br label %9
9: ; preds = %4, %7, %1
%10 = phi i32 [ -1, %1 ], [ %5, %7 ], [ %5, %4 ]
ret i32 %10
}