#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int linux_overcommit_memory_value(void) {
  FILE *fp;
  char buf[64];
  if ((fp = fopen("/proc/sys/vm/overcommit_memory", "r")) == NULL)
    return -1;
  if (fgets(buf, 64, fp) == NULL) {
    fclose(fp);
    return -1;
  }
  fclose(fp);
  return atoi(buf);
}


x86 assembly (clang, -O0):
<linux_overcommit_memory_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xeb1(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1175 <linux_overcommit_memory_value+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <linux_overcommit_memory_value+0x7b>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x40,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11a6 <linux_overcommit_memory_value+0x66>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <linux_overcommit_memory_value+0x7b>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x50(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linux_overcommit_memory_value>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xeb1(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1050 <fopen@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1192 <linux_overcommit_memory_value+0x52>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r14,%r14
je     1192 <linux_overcommit_memory_value+0x52>
mov    %rsp,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"/proc/sys/vm/overcommit_memory\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @linux_overcommit_memory_value() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [64 x i8]
%4 = call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 -1, i32* %1
br label %20
7: ; preds = %0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%9 = load i32*, i32** %2
%10 = call i32* @fgets(i8* %8, i32 64, i32* %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
store i32 -1, i32* %1
br label %20
15: ; preds = %7
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %1
br label %20
20: ; preds = %15, %12, %6
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [31 x i8] c"/proc/sys/vm/overcommit_memory\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @linux_overcommit_memory_value() {
%1 = alloca [64 x i8]
%2 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %11, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 64, i32* %3)
%7 = icmp eq i32* %6, null
%8 = call i32 @fclose(i32* %3)
br i1 %7, label %11, label %9
9: ; preds = %5
%10 = call i32 @atoi(i8* %2)
br label %11
11: ; preds = %5, %0, %9
%12 = phi i32 [ %10, %9 ], [ -1, %0 ], [ -1, %5 ]
ret i32 %12
}