#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 EINVAL;
int /*<<< orphan*/ free(char *);
scalar_t__ parse_xargs(char *, size_t, char ***);
char *read_file(char *, size_t *);
int fetchve(char ***argv) {
  char *cmdline = NULL;
  size_t cmdline_size;
  cmdline = read_file("/proc/self/cmdline", &cmdline_size);
  if (!cmdline)
    goto error;
  if (parse_xargs(cmdline, cmdline_size, argv) <= 0)
    goto error;
  return 0;
error:
  free(cmdline);
  return -EINVAL;
}


x86 assembly (clang, -O0):
<fetchve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xeb5(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <read_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <fetchve+0x38>
jmp    1194 <fetchve+0x64>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <parse_xargs@plt>
cmp    $0x0,%rax
jg     1188 <fetchve+0x58>
jmp    1194 <fetchve+0x64>
movl   $0x0,-0x4(%rbp)
jmp    11ab <fetchve+0x7b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
mov    0x2e3a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fetchve>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
mov    %rsp,%rsi
call   1050 <read_file@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1167 <fetchve+0x37>
mov    (%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <parse_xargs@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jg     117a <fetchve+0x4a>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2e6a(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/proc/self/cmdline\00"
@EINVAL = global i32 0
define i32 @fetchve(i8*** %0) {
%2 = alloca i32
%3 = alloca i8***
%4 = alloca i8*
%5 = alloca i64
store i8*** %0, i8**** %3
store i8* null, i8** %4
%6 = call i8* @read_file(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64* %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
br label %18
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = load i64, i64* %5
%13 = load i8***, i8**** %3
%14 = call i64 @parse_xargs(i8* %11, i64 %12, i8*** %13)
%15 = icmp sle i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
br label %18
17: ; preds = %10
store i32 0, i32* %2
br label %23
18: ; preds = %16, %9
%19 = load i8*, i8** %4
%20 = call i32 @free(i8* %19)
%21 = load i32, i32* @EINVAL
%22 = sub nsw i32 0, %21
store i32 %22, i32* %2
br label %23
23: ; preds = %18, %17
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [19 x i8] c"/proc/self/cmdline\00"
@EINVAL = global i32 0
define i32 @fetchve(i8*** %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to i8*
%4 = call i8* @read_file(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64* %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i64, i64* %2
%8 = call i64 @parse_xargs(i8* %4, i64 %7, i8*** %0)
%9 = icmp slt i64 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %6, %1
%11 = call i32 @free(i8* %4)
%12 = load i32, i32* @EINVAL
%13 = sub nsw i32 0, %12
br label %14
14: ; preds = %6, %10
%15 = phi i32 [ %13, %10 ], [ 0, %6 ]
ret i32 %15
}