#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 */
long INT_MAX;
long INT_MIN;
char *getenv(char *);
long strtol(char const *, char **, int);
int posix2_version(void) {
  long int v = 0;
  char const *s = getenv("_POSIX2_VERSION");
  if (s && *s) {
    char *e;
    long int i = strtol(s, &e, 10);
    if (!*e)
      v = i;
  }
  return v < INT_MIN ? INT_MIN : v < INT_MAX ? v : INT_MAX;
}


x86 assembly (clang, -O0):
<posix2_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xec9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118b <posix2_version+0x6b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118b <posix2_version+0x6b>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1186 <posix2_version+0x66>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    118b <posix2_version+0x6b>
mov    -0x8(%rbp),%rax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%rax
jge    11b2 <posix2_version+0x92>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    11e9 <posix2_version+0xc9>
mov    -0x8(%rbp),%rax
mov    0x2e2b(%rip),%rcx
cmp    (%rcx),%rax
jge    11d3 <posix2_version+0xb3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11e1 <posix2_version+0xc1>
mov    0x2e0e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<posix2_version>:
push   %rax
lea    0xed8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1156 <posix2_version+0x36>
cmpb   $0x0,(%rax)
je     1156 <posix2_version+0x36>
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    (%rsp),%rdx
xor    %ecx,%ecx
cmpb   $0x0,(%rdx)
cmove  %rax,%rcx
jmp    1158 <posix2_version+0x38>
xor    %ecx,%ecx
mov    0x2e81(%rip),%rax
mov    0x2e82(%rip),%rdx
mov    (%rdx),%rdx
cmp    %rdx,%rcx
cmovl  %ecx,%edx
mov    (%rax),%rax
cmp    %rax,%rcx
cmovge %edx,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"_POSIX2_VERSION\00"
@INT_MIN = global i64 0
@INT_MAX = global i64 0
define i32 @posix2_version() {
%1 = alloca i64
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i64 0, i64* %1
%5 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %22
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i64 @strtol(i8* %14, i8** %3, i32 10)
store i64 %15, i64* %4
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = load i64, i64* %4
store i64 %20, i64* %1
br label %21
21: ; preds = %19, %13
br label %22
22: ; preds = %21, %8, %0
%23 = load i64, i64* %1
%24 = load i64, i64* @INT_MIN
%25 = icmp slt i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i64, i64* @INT_MIN
br label %38
28: ; preds = %22
%29 = load i64, i64* %1
%30 = load i64, i64* @INT_MAX
%31 = icmp slt i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = load i64, i64* %1
br label %36
34: ; preds = %28
%35 = load i64, i64* @INT_MAX
br label %36
36: ; preds = %34, %32
%37 = phi i64 [ %33, %32 ], [ %35, %34 ]
br label %38
38: ; preds = %36, %26
%39 = phi i64 [ %27, %26 ], [ %37, %36 ]
%40 = trunc i64 %39 to i32
ret i32 %40
}

LLVM IR (-O2):
@.str = [16 x i8] c"_POSIX2_VERSION\00"
@INT_MIN = global i64 0
@INT_MAX = global i64 0
define i32 @posix2_version() {
%1 = alloca i8*
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %14, label %4
4: ; preds = %0
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = bitcast i8** %1 to i8*
%9 = call i64 @strtol(i8* %2, i8** %1, i32 10)
%10 = load i8*, i8** %1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = select i1 %12, i64 %9, i64 0
br label %14
14: ; preds = %7, %4, %0
%15 = phi i64 [ %13, %7 ], [ 0, %4 ], [ 0, %0 ]
%16 = load i64, i64* @INT_MIN
%17 = icmp slt i64 %15, %16
%18 = load i64, i64* @INT_MAX
%19 = icmp slt i64 %15, %18
%20 = select i1 %19, i64 %15, i64 %18
%21 = select i1 %17, i64 %16, i64 %20
%22 = trunc i64 %21 to i32
ret i32 %22
}