#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 atoi(char *);
char *getenv(char const *);
int oc_env_parse_int(const char *name, int def, int *out) {
  char *str;
  str = getenv(name);
  if (str == NULL) {
    *out = def;
    return 0;
  }
  int ret = atoi(str);
  if (ret == 0) {
    return -1;
  }
  *out = ret;
  return 0;
}


x86 assembly (clang, -O0):
<oc_env_parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1160 <oc_env_parse_int+0x40>
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1192 <oc_env_parse_int+0x72>
mov    -0x28(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1182 <oc_env_parse_int+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <oc_env_parse_int+0x72>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oc_env_parse_int>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
call   1030 <getenv@plt>
test   %rax,%rax
je     1140 <oc_env_parse_int+0x20>
mov    %rax,%rdi
call   1040 <atoi@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1146 <oc_env_parse_int+0x26>
mov    %ebp,(%rbx)
xor    %eax,%eax
jmp    114b <oc_env_parse_int+0x2b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @oc_env_parse_int(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = call i8* @getenv(i8* %10)
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* %6
%16 = load i32*, i32** %7
store i32 %15, i32* %16
store i32 0, i32* %4
br label %26
17: ; preds = %3
%18 = load i8*, i8** %8
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %9
%20 = load i32, i32* %9
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 -1, i32* %4
br label %26
23: ; preds = %17
%24 = load i32, i32* %9
%25 = load i32*, i32** %7
store i32 %24, i32* %25
store i32 0, i32* %4
br label %26
26: ; preds = %23, %22, %14
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
define i32 @oc_env_parse_int(i8* nocapture %0, i32 %1, i32* nocapture writeonly %2) {
%4 = tail call i8* @getenv(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i32 @atoi(i8* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6, %3
%10 = phi i32 [ %1, %3 ], [ %7, %6 ]
store i32 %10, i32* %2
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ -1, %6 ], [ 0, %9 ]
ret i32 %12
}