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

/* Variables and functions */
long atol(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char *, char const *, int);
char *strrchr(char *, char);
int litTotalMemory(long *lMemory) {
  const char *prefixe = "MemTotal";
  FILE *fFile;
  char ligne[300 + 1];
  char *pos;
  int ok = 0;
  fFile = fopen("/tmp/wrekavalid.tmp", "r");
  if (!fFile)
    return 0;
  while (!feof(fFile)) {
    fgets(ligne, sizeof(ligne), fFile);
    if (!strncmp(ligne, prefixe, strlen(prefixe))) {
      pos = strrchr(ligne, ':') + 2;
      if (!pos)
        break;
      if (pos[strlen(pos) - 1] == '\n')
        pos[strlen(pos) - 1] = '\0';
      strcpy(ligne, pos);
      *lMemory = atol(ligne);
      ok = 1;
      break;
    }
  }
  fclose(fFile);
  return ok;
}


x86 assembly (clang, -O0):
<litTotalMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe5a(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x15c(%rbp)
lea    0xe4e(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e2 <litTotalMemory+0x52>
movl   $0x0,-0x4(%rbp)
jmp    133b <litTotalMemory+0x1ab>
jmp    11e7 <litTotalMemory+0x57>
mov    -0x20(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1205 <litTotalMemory+0x75>
jmp    1329 <litTotalMemory+0x199>
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x12d,%esi
call   1080 <fgets@plt>
lea    -0x150(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x170(%rbp),%rdi
mov    -0x168(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1324 <litTotalMemory+0x194>
lea    -0x150(%rbp),%rdi
mov    $0x3a,%esi
call   1070 <strrchr@plt>
add    $0x2,%rax
mov    %rax,-0x158(%rbp)
cmpq   $0x0,-0x158(%rbp)
jne    1289 <litTotalMemory+0xf9>
jmp    1329 <litTotalMemory+0x199>
mov    -0x158(%rbp),%rax
mov    %rax,-0x178(%rbp)
mov    -0x158(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x178(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    12ec <litTotalMemory+0x15c>
mov    -0x158(%rbp),%rax
mov    %rax,-0x180(%rbp)
mov    -0x158(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x180(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x150(%rbp),%rdi
mov    -0x158(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x150(%rbp),%rdi
call   10a0 <atol@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x15c(%rbp)
jmp    1329 <litTotalMemory+0x199>
jmp    11e7 <litTotalMemory+0x57>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x15c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<litTotalMemory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x130,%rsp
mov    %rdi,%r14
lea    0xe60(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     125e <litTotalMemory+0xce>
mov    %rax,%rbx
mov    %rsp,%r15
lea    0xe35(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1262 <litTotalMemory+0xd2>
mov    %r15,%rdi
mov    $0x12d,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11d0 <litTotalMemory+0x40>
mov    %rsp,%rdi
mov    $0x3a,%esi
call   1070 <strrchr@plt>
mov    %rax,%rbp
lea    0x2(%rax),%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0xa,0x1(%rax,%rbp,1)
jne    123e <litTotalMemory+0xae>
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
call   10a0 <atol@plt>
mov    %rax,(%r14)
mov    $0x1,%ebp
jmp    1264 <litTotalMemory+0xd4>
xor    %ebp,%ebp
jmp    126c <litTotalMemory+0xdc>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %ebp,%eax
add    $0x130,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"MemTotal\00"
@.str.1 = [20 x i8] c"/tmp/wrekavalid.tmp\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @litTotalMemory(i64* %0) {
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [301 x i8]
%7 = alloca i8*
%8 = alloca i32
store i64* %0, i64** %3
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %4
store i32 0, i32* %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 0, i32* %2
br label %65
13: ; preds = %1
br label %14
14: ; preds = %60, %13
%15 = load i32*, i32** %5
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %61
19: ; preds = %14
%20 = getelementptr inbounds [301 x i8], [301 x i8]* %6, i64 0, i64 0
%21 = load i32*, i32** %5
%22 = call i32 @fgets(i8* %20, i32 301, i32* %21)
%23 = getelementptr inbounds [301 x i8], [301 x i8]* %6, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = load i8*, i8** %4
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @strncmp(i8* %23, i8* %24, i32 %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %60, label %29
29: ; preds = %19
%30 = getelementptr inbounds [301 x i8], [301 x i8]* %6, i64 0, i64 0
%31 = call i8* @strrchr(i8* %30, i8 signext 58)
%32 = getelementptr inbounds i8, i8* %31, i64 2
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = icmp ne i8* %33, null
br i1 %34, label %36, label %35
35: ; preds = %29
br label %61
36: ; preds = %29
%37 = load i8*, i8** %7
%38 = load i8*, i8** %7
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %37, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 10
br i1 %45, label %46, label %53
46: ; preds = %36
%47 = load i8*, i8** %7
%48 = load i8*, i8** %7
%49 = call i32 @strlen(i8* %48)
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %47, i64 %51
store i8 0, i8* %52
br label %53
53: ; preds = %46, %36
%54 = getelementptr inbounds [301 x i8], [301 x i8]* %6, i64 0, i64 0
%55 = load i8*, i8** %7
%56 = call i32 @strcpy(i8* %54, i8* %55)
%57 = getelementptr inbounds [301 x i8], [301 x i8]* %6, i64 0, i64 0
%58 = call i64 @atol(i8* %57)
%59 = load i64*, i64** %3
store i64 %58, i64* %59
store i32 1, i32* %8
br label %61
60: ; preds = %19
br label %14
61: ; preds = %53, %35, %14
%62 = load i32*, i32** %5
%63 = call i32 @fclose(i32* %62)
%64 = load i32, i32* %8
store i32 %64, i32* %2
br label %65
65: ; preds = %61, %12
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
@.str = [9 x i8] c"MemTotal\00"
@.str.1 = [20 x i8] c"/tmp/wrekavalid.tmp\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @litTotalMemory(i64* nocapture writeonly %0) {
%2 = alloca [301 x i8]
%3 = getelementptr inbounds [301 x i8], [301 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %34, label %6
6: ; preds = %1, %9
%7 = call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %31
9: ; preds = %6
%10 = call i32 @fgets(i8* %3, i32 301, i32* %4)
%11 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %9
%15 = call i8* @strrchr(i8* %3, i8 signext 58)
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %23, label %28
23: ; preds = %14
%24 = call i32 @strlen(i8* %16)
%25 = add nsw i32 %24, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %16, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %23, %14
%29 = call i32 @strcpy(i8* %3, i8* %16)
%30 = call i64 @atol(i8* %3)
store i64 %30, i64* %0
br label %31
31: ; preds = %6, %28
%32 = phi i32 [ 1, %28 ], [ 0, %6 ]
%33 = call i32 @fclose(i32* %4)
br label %34
34: ; preds = %1, %31
%35 = phi i32 [ %32, %31 ], [ 0, %1 ]
ret i32 %35
}