#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 get_info_infile(char *, char *, size_t *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char *,
                            char *);
size_t cgmemstat(char *cg, char *stat) {
  char fn[256];
  size_t ret;
  snprintf(fn, 256, "%s/%s%s/%s", "/sys/fs/cgroup", "memory", cg,
           "memory.stat");
  if (get_info_infile(fn, stat, &ret) == -1)
    return 0;
  return (ret / 1024);
}


x86 assembly (clang, -O0):
<cgmemstat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%r9
mov    $0x100,%esi
lea    0xeb6(%rip),%rdx
lea    0xeba(%rip),%rcx
lea    0xec2(%rip),%r8
lea    0xec2(%rip),%rax
mov    %rax,(%rsp)
call   1040 <snprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x128(%rbp),%rdx
call   1030 <get_info_infile@plt>
cmp    $0xffffffff,%eax
jne    1195 <cgmemstat+0x75>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <cgmemstat+0x84>
mov    -0x128(%rbp),%rax
shr    $0xa,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgmemstat>:
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    %rdi,%r9
lea    0xeea(%rip),%rax
mov    %rax,(%rsp)
lea    0xebe(%rip),%rdx
lea    0xec2(%rip),%rcx
lea    0xeca(%rip),%r8
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <get_info_infile@plt>
mov    0x8(%rsp),%rdx
shr    $0xa,%rdx
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
cmovne %rdx,%rcx
mov    %rcx,%rax
add    $0x118,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s/%s%s/%s\00"
@.str.1 = [15 x i8] c"/sys/fs/cgroup\00"
@.str.2 = [7 x i8] c"memory\00"
@.str.3 = [12 x i8] c"memory.stat\00"
define i64 @cgmemstat(i8* %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @get_info_infile(i8* %11, i8* %12, i64* %7)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %2
store i64 0, i64* %3
br label %19
16: ; preds = %2
%17 = load i64, i64* %7
%18 = udiv i64 %17, 1024
store i64 %18, i64* %3
br label %19
19: ; preds = %16, %15
%20 = load i64, i64* %3
ret i64 %20
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s/%s%s/%s\00"
@.str.1 = [15 x i8] c"/sys/fs/cgroup\00"
@.str.2 = [7 x i8] c"memory\00"
@.str.3 = [12 x i8] c"memory.stat\00"
define i64 @cgmemstat(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca i64
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast i64* %4 to i8*
%7 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @get_info_infile(i8* %5, i8* %1, i64* %4)
%9 = icmp eq i32 %8, -1
%10 = load i64, i64* %4
%11 = lshr i64 %10, 10
%12 = select i1 %9, i64 0, i64 %11
ret i64 %12
}