#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*/ log_error(char *, int);
int parse_meminfo_field(char const *, unsigned int const, char *,
                        unsigned int *);
int parse_meminfo(const char *meminfo, const unsigned int size,
                  unsigned int *total, unsigned int *used,
                  unsigned int *buffers, unsigned int *cached) {
  int err = 0;
  unsigned int free;
  err = parse_meminfo_field(meminfo, size, "MemTotal", total);
  if (err) {
    log_error("Error parsing MemTotal: %d", err);
    return err;
  }
  err = parse_meminfo_field(meminfo, size, "MemFree", &free);
  if (err) {
    log_error("Error parsing MemFree: %d", err);
    return err;
  }
  err = parse_meminfo_field(meminfo, size, "Buffers", buffers);
  if (err) {
    log_error("Error parsing Buffers: %d", err);
    return err;
  }
  err = parse_meminfo_field(meminfo, size, "Cached", cached);
  if (err) {
    log_error("Error parsing Cached: %d", err);
    return err;
  }
  *used = *total - free;
  return err;
}


x86 assembly (clang, -O0):
<parse_meminfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
lea    0xea8(%rip),%rdx
call   1030 <parse_meminfo_field@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1184 <parse_meminfo+0x64>
mov    -0x3c(%rbp),%esi
lea    0xe95(%rip),%rdi
call   1040 <log_error@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <parse_meminfo+0x133>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xe92(%rip),%rdx
lea    -0x40(%rbp),%rcx
call   1030 <parse_meminfo_field@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     11c2 <parse_meminfo+0xa2>
mov    -0x3c(%rbp),%esi
lea    0xe7a(%rip),%rdi
call   1040 <log_error@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <parse_meminfo+0x133>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rcx
lea    0xe72(%rip),%rdx
call   1030 <parse_meminfo_field@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1200 <parse_meminfo+0xe0>
mov    -0x3c(%rbp),%esi
lea    0xe5e(%rip),%rdi
call   1040 <log_error@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <parse_meminfo+0x133>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rcx
lea    0xe56(%rip),%rdx
call   1030 <parse_meminfo_field@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     123e <parse_meminfo+0x11e>
mov    -0x3c(%rbp),%esi
lea    0xe41(%rip),%rdi
call   1040 <log_error@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <parse_meminfo+0x133>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
sub    -0x40(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_meminfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%r12
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,%rbx
lea    0xeb7(%rip),%rdx
mov    %r14,%rcx
call   1030 <parse_meminfo_field@plt>
test   %eax,%eax
je     1160 <parse_meminfo+0x40>
mov    %eax,%ebp
lea    0xeab(%rip),%rdi
jmp    11d5 <parse_meminfo+0xb5>
mov    %r12,0x8(%rsp)
lea    0xeb8(%rip),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
mov    %r13d,%esi
call   1030 <parse_meminfo_field@plt>
test   %eax,%eax
je     118b <parse_meminfo+0x6b>
mov    %eax,%ebp
lea    0xea3(%rip),%rdi
jmp    11d5 <parse_meminfo+0xb5>
lea    0xeb4(%rip),%rdx
mov    %rbx,%rdi
mov    %r13d,%esi
mov    0x8(%rsp),%rcx
call   1030 <parse_meminfo_field@plt>
test   %eax,%eax
je     11b1 <parse_meminfo+0x91>
mov    %eax,%ebp
lea    0xe9f(%rip),%rdi
jmp    11d5 <parse_meminfo+0xb5>
lea    0xeb0(%rip),%rdx
mov    %rbx,%rdi
mov    %r13d,%esi
mov    0x10(%rsp),%rcx
call   1030 <parse_meminfo_field@plt>
test   %eax,%eax
je     11ed <parse_meminfo+0xcd>
mov    %eax,%ebp
lea    0xe9a(%rip),%rdi
mov    %ebp,%esi
call   1040 <log_error@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%eax
sub    0x4(%rsp),%eax
mov    %eax,(%r15)
xor    %ebp,%ebp
jmp    11dc <parse_meminfo+0xbc>

LLVM IR (-O0):
@.str = [9 x i8] c"MemTotal\00"
@.str.1 = [27 x i8] c"Error parsing MemTotal: %d\00"
@.str.2 = [8 x i8] c"MemFree\00"
@.str.3 = [26 x i8] c"Error parsing MemFree: %d\00"
@.str.4 = [8 x i8] c"Buffers\00"
@.str.5 = [26 x i8] c"Error parsing Buffers: %d\00"
@.str.6 = [7 x i8] c"Cached\00"
@.str.7 = [25 x i8] c"Error parsing Cached: %d\00"
define i32 @parse_meminfo(i8* %0, i32 %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
store i32 0, i32* %14
%16 = load i8*, i8** %8
%17 = load i32, i32* %9
%18 = load i32*, i32** %10
%19 = call i32 @parse_meminfo_field(i8* %16, i32 %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %18)
store i32 %19, i32* %14
%20 = load i32, i32* %14
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %6
%23 = load i32, i32* %14
%24 = call i32 @log_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %14
store i32 %25, i32* %7
br label %65
26: ; preds = %6
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = call i32 @parse_meminfo_field(i8* %27, i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %15)
store i32 %29, i32* %14
%30 = load i32, i32* %14
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i32, i32* %14
%34 = call i32 @log_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %14
store i32 %35, i32* %7
br label %65
36: ; preds = %26
%37 = load i8*, i8** %8
%38 = load i32, i32* %9
%39 = load i32*, i32** %12
%40 = call i32 @parse_meminfo_field(i8* %37, i32 %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32* %39)
store i32 %40, i32* %14
%41 = load i32, i32* %14
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i32, i32* %14
%45 = call i32 @log_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %14
store i32 %46, i32* %7
br label %65
47: ; preds = %36
%48 = load i8*, i8** %8
%49 = load i32, i32* %9
%50 = load i32*, i32** %13
%51 = call i32 @parse_meminfo_field(i8* %48, i32 %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %50)
store i32 %51, i32* %14
%52 = load i32, i32* %14
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %47
%55 = load i32, i32* %14
%56 = call i32 @log_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %14
store i32 %57, i32* %7
br label %65
58: ; preds = %47
%59 = load i32*, i32** %10
%60 = load i32, i32* %59
%61 = load i32, i32* %15
%62 = sub i32 %60, %61
%63 = load i32*, i32** %11
store i32 %62, i32* %63
%64 = load i32, i32* %14
store i32 %64, i32* %7
br label %65
65: ; preds = %58, %54, %43, %32, %22
%66 = load i32, i32* %7
ret i32 %66
}

LLVM IR (-O2):
@.str = [9 x i8] c"MemTotal\00"
@.str.1 = [27 x i8] c"Error parsing MemTotal: %d\00"
@.str.2 = [8 x i8] c"MemFree\00"
@.str.3 = [26 x i8] c"Error parsing MemFree: %d\00"
@.str.4 = [8 x i8] c"Buffers\00"
@.str.5 = [26 x i8] c"Error parsing Buffers: %d\00"
@.str.6 = [7 x i8] c"Cached\00"
@.str.7 = [25 x i8] c"Error parsing Cached: %d\00"
define i32 @parse_meminfo(i8* %0, i32 %1, i32* %2, i32* nocapture writeonly %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = bitcast i32* %7 to i8*
%9 = tail call i32 @parse_meminfo_field(i8* %0, i32 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 @log_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %32
13: ; preds = %6
%14 = call i32 @parse_meminfo_field(i8* %0, i32 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i32 @log_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %32
18: ; preds = %13
%19 = call i32 @parse_meminfo_field(i8* %0, i32 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @log_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i32 %19)
br label %32
23: ; preds = %18
%24 = call i32 @parse_meminfo_field(i8* %0, i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i32 @log_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %24)
br label %32
28: ; preds = %23
%29 = load i32, i32* %2
%30 = load i32, i32* %7
%31 = sub i32 %29, %30
store i32 %31, i32* %3
br label %32
32: ; preds = %28, %26, %21, %16, %11
%33 = phi i32 [ %9, %11 ], [ %14, %16 ], [ %19, %21 ], [ %24, %26 ], [ 0, %28 ]
ret i32 %33
}