#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 unsigned long long uint64_t;
struct glgrab {
  int dummy;
};

/* Variables and functions */
int EINVAL;
char *getenv(char *);
int glgrab_init(struct glgrab *, char const *, unsigned long long,
                unsigned long long);
unsigned long long str2int(char *, unsigned long long);
int glgrab_init_from_env(struct glgrab *g) {
  const char *path = getenv("GLGRAB_MRB");
  if (path == NULL)
    return EINVAL;
  uint64_t bufsize = str2int(getenv("GLGRAB_BUFSIZE"), (256ULL << 20));
  return glgrab_init(g, path, bufsize,
                     str2int(getenv("GLGRAB_MAXFRAME"), bufsize));
}


x86 assembly (clang, -O0):
<glgrab_init_from_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <glgrab_init_from_env+0x38>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cc <glgrab_init_from_env+0x9c>
lea    0xe9c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    $0x10000000,%esi
call   1040 <str2int@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    -0x20(%rbp),%rsi
call   1040 <str2int@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
call   1050 <glgrab_init@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glgrab_init_from_env>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xec1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1195 <glgrab_init_from_env+0x65>
mov    %rax,%r15
lea    0xeb8(%rip),%rdi
call   1030 <getenv@plt>
mov    $0x10000000,%esi
mov    %rax,%rdi
call   1040 <str2int@plt>
mov    %rax,%rbx
lea    0xeab(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <str2int@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <glgrab_init@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.glgrab = type { i32 }
@.str = [11 x i8] c"GLGRAB_MRB\00"
@EINVAL = global i32 0
@.str.1 = [15 x i8] c"GLGRAB_BUFSIZE\00"
@.str.2 = [16 x i8] c"GLGRAB_MAXFRAME\00"
define i32 @glgrab_init_from_env(%struct.glgrab* %0) {
%2 = alloca i32
%3 = alloca %struct.glgrab*
%4 = alloca i8*
%5 = alloca i64
store %struct.glgrab* %0, %struct.glgrab** %3
%6 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* @EINVAL
store i32 %10, i32* %2
br label %21
11: ; preds = %1
%12 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 @str2int(i8* %12, i64 268435456)
store i64 %13, i64* %5
%14 = load %struct.glgrab*, %struct.glgrab** %3
%15 = load i8*, i8** %4
%16 = load i64, i64* %5
%17 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%18 = load i64, i64* %5
%19 = call i64 @str2int(i8* %17, i64 %18)
%20 = call i32 @glgrab_init(%struct.glgrab* %14, i8* %15, i64 %16, i64 %19)
store i32 %20, i32* %2
br label %21
21: ; preds = %11, %9
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.glgrab = type { i32 }
@.str = [11 x i8] c"GLGRAB_MRB\00"
@EINVAL = global i32 0
@.str.1 = [15 x i8] c"GLGRAB_BUFSIZE\00"
@.str.2 = [16 x i8] c"GLGRAB_MAXFRAME\00"
define i32 @glgrab_init_from_env(%struct.glgrab* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i32, i32* @EINVAL
br label %12
6: ; preds = %1
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i64 @str2int(i8* %7, i64 268435456)
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i64 @str2int(i8* %9, i64 %8)
%11 = tail call i32 @glgrab_init(%struct.glgrab* %0, i8* %2, i64 %8, i64 %10)
br label %12
12: ; preds = %6, %4
%13 = phi i32 [ %5, %4 ], [ %11, %6 ]
ret i32 %13
}