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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, long *);
int /*<<< orphan*/ strncmp(char *, char const *, size_t const);
int /*<<< orphan*/ warn(char *);
int get_swap_info(long *s_total, long *s_free, long *s_cached) {
  FILE *fp;
  struct {
    const char *name;
    const size_t len;
    long *var;
  } ent[] = {
      {"SwapTotal", sizeof("SwapTotal") - 1, s_total},
      {"SwapFree", sizeof("SwapFree") - 1, s_free},
      {"SwapCached", sizeof("SwapCached") - 1, s_cached},
  };
  size_t line_len = 0, i, left;
  char *line = NULL;
  for (i = 0, left = 0; i < (sizeof(ent) / sizeof *(ent)); i++) {
    if (ent[i].var) {
      left++;
    }
  }
  if (!(fp = fopen("/proc/meminfo", "r"))) {
    warn("fopen '/proc/meminfo':");
    return 1;
  }
  while (left > 0 && getline(&line, &line_len, fp) >= 0) {
    for (i = 0; i < (sizeof(ent) / sizeof *(ent)); i++) {
      if (ent[i].var && !strncmp(line, ent[i].name, ent[i].len)) {
        sscanf(line + ent[i].len + 1, "%ld kB\n", ent[i].var);
        left--;
        break;
      }
    }
  }
  free(line);
  if (ferror(fp)) {
    warn("getline '/proc/meminfo':");
    return 1;
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<get_swap_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe62(%rip),%rax
mov    %rax,-0x70(%rbp)
movq   $0x9,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    0xe51(%rip),%rax
mov    %rax,-0x58(%rbp)
movq   $0x8,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    0xe3f(%rip),%rax
mov    %rax,-0x40(%rbp)
movq   $0xa,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x78(%rbp)
movq   $0x0,-0x90(%rbp)
movq   $0x0,-0x80(%rbp)
movq   $0x0,-0x88(%rbp)
cmpq   $0x3,-0x80(%rbp)
jae    1258 <get_swap_info+0xd8>
lea    -0x70(%rbp),%rax
imul   $0x18,-0x80(%rbp),%rcx
add    %rcx,%rax
cmpq   $0x0,0x10(%rax)
je     1242 <get_swap_info+0xc2>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    1247 <get_swap_info+0xc7>
mov    -0x80(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80(%rbp)
jmp    120e <get_swap_info+0x8e>
lea    0xdbf(%rip),%rdi
lea    0xdc6(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1291 <get_swap_info+0x111>
lea    0xdae(%rip),%rdi
call   1050 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ee <get_swap_info+0x26e>
jmp    1296 <get_swap_info+0x116>
xor    %eax,%eax
cmpq   $0x0,-0x88(%rbp)
mov    %al,-0x91(%rbp)
jbe    12cd <get_swap_info+0x14d>
mov    -0x28(%rbp),%rdx
lea    -0x90(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   10a0 <getline@plt>
cmp    $0x0,%rax
setge  %al
mov    %al,-0x91(%rbp)
mov    -0x91(%rbp),%al
test   $0x1,%al
jne    12e0 <get_swap_info+0x160>
jmp    13a7 <get_swap_info+0x227>
movq   $0x0,-0x80(%rbp)
cmpq   $0x3,-0x80(%rbp)
jae    13a2 <get_swap_info+0x222>
lea    -0x70(%rbp),%rax
imul   $0x18,-0x80(%rbp),%rcx
add    %rcx,%rax
cmpq   $0x0,0x10(%rax)
je     138c <get_swap_info+0x20c>
mov    -0x90(%rbp),%rdi
lea    -0x70(%rbp),%rax
imul   $0x18,-0x80(%rbp),%rcx
add    %rcx,%rax
mov    (%rax),%rsi
lea    -0x70(%rbp),%rax
imul   $0x18,-0x80(%rbp),%rcx
add    %rcx,%rax
mov    0x8(%rax),%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    138c <get_swap_info+0x20c>
mov    -0x90(%rbp),%rdi
lea    -0x70(%rbp),%rax
imul   $0x18,-0x80(%rbp),%rcx
add    %rcx,%rax
add    0x8(%rax),%rdi
add    $0x1,%rdi
lea    -0x70(%rbp),%rax
imul   $0x18,-0x80(%rbp),%rcx
add    %rcx,%rax
mov    0x10(%rax),%rdx
lea    0xcd5(%rip),%rsi
call   1080 <sscanf@plt>
mov    -0x88(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x88(%rbp)
jmp    13a2 <get_swap_info+0x222>
jmp    1391 <get_swap_info+0x211>
mov    -0x80(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80(%rbp)
jmp    12e8 <get_swap_info+0x168>
jmp    1296 <get_swap_info+0x116>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1060 <ferror@plt>
cmp    $0x0,%rax
je     13de <get_swap_info+0x25e>
lea    0xc80(%rip),%rdi
call   1050 <warn@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ee <get_swap_info+0x26e>
mov    -0x28(%rbp),%rdi
call   1070 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_swap_info>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
movq   $0x0,0x20(%rsp)
xor    %ebp,%ebp
test   %rdi,%rdi
setne  %bpl
cmp    $0x1,%rsi
sbb    $0xffffffffffffffff,%rbp
movq   $0x0,0x8(%rsp)
cmp    $0x1,%rdx
sbb    $0xffffffffffffffff,%rbp
lea    0xe55(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12f7 <get_swap_info+0x177>
mov    %rax,%r15
test   %rbp,%rbp
je     1300 <get_swap_info+0x180>
mov    %r14,0x18(%rsp)
jmp    1221 <get_swap_info+0xa1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r14,%r13,1),%rdi
add    $0x1,%rdi
lea    0xe36(%rip),%rsi
call   1080 <sscanf@plt>
add    $0xffffffffffffffff,%rbp
test   %rbp,%rbp
je     12f0 <get_swap_info+0x170>
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    %r15,%rdx
call   10a0 <getline@plt>
test   %rax,%rax
js     12f0 <get_swap_info+0x170>
mov    0x8(%rsp),%r13
test   %rbx,%rbx
je     1267 <get_swap_info+0xe7>
mov    $0x9,%r14d
mov    $0x9,%edx
mov    %r13,%rdi
lea    0xda5(%rip),%rsi
call   1040 <strncmp@plt>
mov    %rbx,%rdx
test   %eax,%eax
je     1200 <get_swap_info+0x80>
test   %r12,%r12
je     1291 <get_swap_info+0x111>
mov    $0x8,%r14d
mov    $0x8,%edx
mov    %r13,%rdi
lea    0xd89(%rip),%rsi
call   1040 <strncmp@plt>
mov    %r12,%rdx
test   %eax,%eax
je     1200 <get_swap_info+0x80>
mov    %rbp,0x10(%rsp)
mov    %rbx,%rbp
mov    %r15,%rbx
mov    0x18(%rsp),%r15
test   %r15,%r15
je     12e0 <get_swap_info+0x160>
mov    $0xa,%r14d
mov    $0xa,%edx
mov    %r13,%rdi
lea    0xd58(%rip),%rsi
call   1040 <strncmp@plt>
mov    %r15,%rdx
test   %eax,%eax
mov    %rbx,%r15
mov    %rbp,%rbx
mov    0x10(%rsp),%rbp
jne    1218 <get_swap_info+0x98>
jmp    1200 <get_swap_info+0x80>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%r15
mov    %rbp,%rbx
mov    0x10(%rsp),%rbp
jmp    1218 <get_swap_info+0x98>
mov    0x8(%rsp),%rdi
jmp    1302 <get_swap_info+0x182>
lea    0xd30(%rip),%rdi
jmp    131b <get_swap_info+0x19b>
xor    %edi,%edi
call   1030 <free@plt>
mov    %r15,%rdi
call   1060 <ferror@plt>
test   %rax,%rax
je     1327 <get_swap_info+0x1a7>
lea    0xd32(%rip),%rdi
call   1050 <warn@plt>
mov    $0x1,%eax
jmp    1331 <get_swap_info+0x1b1>
mov    %r15,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.anon = type { i8*, i64, i64* }
@.str = [10 x i8] c"SwapTotal\00"
@.str.1 = [9 x i8] c"SwapFree\00"
@.str.2 = [11 x i8] c"SwapCached\00"
@.str.3 = [14 x i8] c"/proc/meminfo\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [23 x i8] c"fopen '/proc/meminfo':\00"
@.str.6 = [8 x i8] c"%ld kB\0A\00"
@.str.7 = [25 x i8] c"getline '/proc/meminfo':\00"
define i32 @get_swap_info(i64* %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca [3 x %struct.anon]
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
store i64* %0, i64** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%14 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %9, i64 0, i64 0
%15 = getelementptr inbounds %struct.anon, %struct.anon* %14, i32 0, i32 0
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds %struct.anon, %struct.anon* %14, i32 0, i32 1
store i64 9, i64* %16
%17 = getelementptr inbounds %struct.anon, %struct.anon* %14, i32 0, i32 2
%18 = load i64*, i64** %5
store i64* %18, i64** %17
%19 = getelementptr inbounds %struct.anon, %struct.anon* %14, i64 1
%20 = getelementptr inbounds %struct.anon, %struct.anon* %19, i32 0, i32 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds %struct.anon, %struct.anon* %19, i32 0, i32 1
store i64 8, i64* %21
%22 = getelementptr inbounds %struct.anon, %struct.anon* %19, i32 0, i32 2
%23 = load i64*, i64** %6
store i64* %23, i64** %22
%24 = getelementptr inbounds %struct.anon, %struct.anon* %19, i64 1
%25 = getelementptr inbounds %struct.anon, %struct.anon* %24, i32 0, i32 0
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %25
%26 = getelementptr inbounds %struct.anon, %struct.anon* %24, i32 0, i32 1
store i64 10, i64* %26
%27 = getelementptr inbounds %struct.anon, %struct.anon* %24, i32 0, i32 2
%28 = load i64*, i64** %7
store i64* %28, i64** %27
store i64 0, i64* %10
store i8* null, i8** %13
store i64 0, i64* %11
store i64 0, i64* %12
br label %29
29: ; preds = %42, %3
%30 = load i64, i64* %11
%31 = icmp ult i64 %30, 3
br i1 %31, label %32, label %45
32: ; preds = %29
%33 = load i64, i64* %11
%34 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %9, i64 0, i64 %33
%35 = getelementptr inbounds %struct.anon, %struct.anon* %34, i32 0, i32 2
%36 = load i64*, i64** %35
%37 = icmp ne i64* %36, null
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = load i64, i64* %12
%40 = add i64 %39, 1
store i64 %40, i64* %12
br label %41
41: ; preds = %38, %32
br label %42
42: ; preds = %41
%43 = load i64, i64* %11
%44 = add i64 %43, 1
store i64 %44, i64* %11
br label %29
45: ; preds = %29
%46 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %46, i32** %8
%47 = icmp ne i32* %46, null
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = call i32 @warn(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %4
br label %113
50: ; preds = %45
br label %51
51: ; preds = %101, %50
%52 = load i64, i64* %12
%53 = icmp ugt i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %51
%55 = load i32*, i32** %8
%56 = call i64 @getline(i8** %13, i64* %10, i32* %55)
%57 = icmp sge i64 %56, 0
br label %58
58: ; preds = %54, %51
%59 = phi i1 [ false, %51 ], [ %57, %54 ]
br i1 %59, label %60, label %102
60: ; preds = %58
store i64 0, i64* %11
br label %61
61: ; preds = %98, %60
%62 = load i64, i64* %11
%63 = icmp ult i64 %62, 3
br i1 %63, label %64, label %101
64: ; preds = %61
%65 = load i64, i64* %11
%66 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %9, i64 0, i64 %65
%67 = getelementptr inbounds %struct.anon, %struct.anon* %66, i32 0, i32 2
%68 = load i64*, i64** %67
%69 = icmp ne i64* %68, null
br i1 %69, label %70, label %97
70: ; preds = %64
%71 = load i8*, i8** %13
%72 = load i64, i64* %11
%73 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %9, i64 0, i64 %72
%74 = getelementptr inbounds %struct.anon, %struct.anon* %73, i32 0, i32 0
%75 = load i8*, i8** %74
%76 = load i64, i64* %11
%77 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %9, i64 0, i64 %76
%78 = getelementptr inbounds %struct.anon, %struct.anon* %77, i32 0, i32 1
%79 = load i64, i64* %78
%80 = call i32 @strncmp(i8* %71, i8* %75, i64 %79)
%81 = icmp ne i32 %80, 0
br i1 %81, label %97, label %82
82: ; preds = %70
%83 = load i8*, i8** %13
%84 = load i64, i64* %11
%85 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %9, i64 0, i64 %84
%86 = getelementptr inbounds %struct.anon, %struct.anon* %85, i32 0, i32 1
%87 = load i64, i64* %86
%88 = getelementptr inbounds i8, i8* %83, i64 %87
%89 = getelementptr inbounds i8, i8* %88, i64 1
%90 = load i64, i64* %11
%91 = getelementptr inbounds [3 x %struct.anon], [3 x %struct.anon]* %9, i64 0, i64 %90
%92 = getelementptr inbounds %struct.anon, %struct.anon* %91, i32 0, i32 2
%93 = load i64*, i64** %92
%94 = call i32 @sscanf(i8* %89, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i64* %93)
%95 = load i64, i64* %12
%96 = add i64 %95, -1
store i64 %96, i64* %12
br label %101
97: ; preds = %70, %64
br label %98
98: ; preds = %97
%99 = load i64, i64* %11
%100 = add i64 %99, 1
store i64 %100, i64* %11
br label %61
101: ; preds = %82, %61
br label %51
102: ; preds = %58
%103 = load i8*, i8** %13
%104 = call i32 @free(i8* %103)
%105 = load i32*, i32** %8
%106 = call i64 @ferror(i32* %105)
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %102
%109 = call i32 @warn(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %4
br label %113
110: ; preds = %102
%111 = load i32*, i32** %8
%112 = call i32 @fclose(i32* %111)
store i32 0, i32* %4
br label %113
113: ; preds = %110, %108, %48
%114 = load i32, i32* %4
ret i32 %114
}

LLVM IR (-O2):
@.str = [10 x i8] c"SwapTotal\00"
@.str.1 = [9 x i8] c"SwapFree\00"
@.str.2 = [11 x i8] c"SwapCached\00"
@.str.3 = [14 x i8] c"/proc/meminfo\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [23 x i8] c"fopen '/proc/meminfo':\00"
@.str.6 = [8 x i8] c"%ld kB\0A\00"
@.str.7 = [25 x i8] c"getline '/proc/meminfo':\00"
define i32 @get_swap_info(i64* %0, i64* %1, i64* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%8 = icmp ne i64* %0, null
%9 = zext i1 %8 to i64
%10 = icmp ne i64* %1, null
%11 = zext i1 %10 to i64
%12 = add nuw nsw i64 %9, %11
%13 = icmp ne i64* %2, null
%14 = zext i1 %13 to i64
%15 = add nuw nsw i64 %12, %14
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %24, label %18
18: ; preds = %3
%19 = icmp eq i64 %15, 0
br i1 %19, label %55, label %20
20: ; preds = %18
%21 = icmp eq i64* %0, null
%22 = icmp eq i64* %1, null
%23 = icmp eq i64* %2, null
br label %26
24: ; preds = %3
%25 = tail call i32 @warn(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %64
26: ; preds = %20, %50
%27 = phi i64 [ %51, %50 ], [ %15, %20 ]
%28 = call i64 @getline(i8** %5, i64* %4, i32* %16)
%29 = icmp sgt i64 %28, -1
br i1 %29, label %30, label %53
30: ; preds = %26
%31 = load i8*, i8** %5
br i1 %21, label %42, label %32
32: ; preds = %30
%33 = call i32 @strncmp(i8* dereferenceable(1) %31, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 9)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %47, %43, %32
%36 = phi i64* [ %0, %32 ], [ %1, %43 ], [ %2, %47 ]
%37 = phi i64 [ 9, %32 ], [ 8, %43 ], [ 10, %47 ]
%38 = getelementptr inbounds i8, i8* %31, i64 1
%39 = getelementptr inbounds i8, i8* %38, i64 %37
%40 = call i32 @sscanf(i8* %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i64* %36)
%41 = add i64 %27, -1
br label %50
42: ; preds = %30, %32
br i1 %22, label %46, label %43
43: ; preds = %42
%44 = call i32 @strncmp(i8* dereferenceable(1) %31, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 8)
%45 = icmp eq i32 %44, 0
br i1 %45, label %35, label %46
46: ; preds = %43, %42
br i1 %23, label %50, label %47
47: ; preds = %46
%48 = call i32 @strncmp(i8* dereferenceable(1) %31, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 10)
%49 = icmp eq i32 %48, 0
br i1 %49, label %35, label %50
50: ; preds = %46, %47, %35
%51 = phi i64 [ %41, %35 ], [ %27, %47 ], [ %27, %46 ]
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %26
53: ; preds = %50, %26
%54 = load i8*, i8** %5
br label %55
55: ; preds = %53, %18
%56 = phi i8* [ %54, %53 ], [ null, %18 ]
%57 = call i32 @free(i8* %56)
%58 = call i64 @ferror(i32* %16)
%59 = icmp eq i64 %58, 0
br i1 %59, label %62, label %60
60: ; preds = %55
%61 = call i32 @warn(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
br label %64
62: ; preds = %55
%63 = call i32 @fclose(i32* %16)
br label %64
64: ; preds = %62, %60, %24
%65 = phi i32 [ 1, %60 ], [ 0, %62 ], [ 1, %24 ]
ret i32 %65
}