#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *grideye_plugin_init_v2(int);
scalar_t__ mem_read_exit();
scalar_t__ mem_read_test(int /*<<< orphan*/, char **);
int /*<<< orphan*/ stdout;
int main() {
  char *str = NULL;
  if (grideye_plugin_init_v2(2) == NULL)
    return -1;
  if (mem_read_test(0, &str) < 0)
    return -1;
  fprintf(stdout, "%s\n", str);
  free(str);
  if (mem_read_exit() < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x2,%edi
call   1050 <grideye_plugin_init_v2@plt>
cmp    $0x0,%rax
jne    1187 <main+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <main+0x9e>
xor    %edi,%edi
lea    -0x10(%rbp),%rsi
call   1040 <mem_read_test@plt>
cmp    $0x0,%rax
jge    11a8 <main+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <main+0x9e>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe44(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1070 <mem_read_exit@plt>
cmp    $0x0,%rax
jge    11e7 <main+0x97>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <main+0x9e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
mov    $0x2,%edi
call   1050 <grideye_plugin_init_v2@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11b5 <main+0x65>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1040 <mem_read_test@plt>
test   %rax,%rax
js     11b5 <main+0x65>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xe68(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1070 <mem_read_exit@plt>
mov    %rax,%rbx
sar    $0x3f,%rbx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %2
%3 = call i32* @grideye_plugin_init_v2(i32 2)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %6
5: ; preds = %0
store i32 -1, i32* %1
br label %20
6: ; preds = %0
%7 = call i64 @mem_read_test(i32 0, i8** %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %6
store i32 -1, i32* %1
br label %20
10: ; preds = %6
%11 = load i32, i32* @stdout
%12 = load i8*, i8** %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
%16 = call i64 (...) @mem_read_exit()
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %10
store i32 -1, i32* %1
br label %20
19: ; preds = %10
store i32 0, i32* %1
br label %20
20: ; preds = %19, %18, %9, %5
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%3 = tail call i32* @grideye_plugin_init_v2(i32 2)
%4 = icmp eq i32* %3, null
br i1 %4, label %17, label %5
5: ; preds = %0
%6 = call i64 @mem_read_test(i32 0, i8** %1)
%7 = icmp slt i64 %6, 0
br i1 %7, label %17, label %8
8: ; preds = %5
%9 = load i32, i32* @stdout
%10 = load i8*, i8** %1
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %1
%13 = call i32 @free(i8* %12)
%14 = call i64 (...) @mem_read_exit()
%15 = ashr i64 %14, 63
%16 = trunc i64 %15 to i32
br label %17
17: ; preds = %8, %5, %0
%18 = phi i32 [ -1, %0 ], [ -1, %5 ], [ %16, %8 ]
ret i32 %18
}