#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, long *);
int /*<<< orphan*/ sprintf(char *, char *, double);
int /*<<< orphan*/ strcmp(char *, char *);
void swap_free(char *buf) {
  FILE *f;
  long tot, fr;
  long n;
  char s[0x100];
  f = fopen("/proc/meminfo", "r");
  while (!feof(f)) {
    fscanf(f, "%s %ld %*s\n", s, &n);
    if (!strcmp(s, "SwapTotal:"))
      tot = n;
    else if (!strcmp(s, "SwapFree:"))
      fr = n;
  }
  fclose(f);
  sprintf(buf, "%.1f", 100.0 * fr / tot);
}


x86 assembly (clang, -O0):
<swap_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe92(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a4 <swap_free+0x44>
jmp    1216 <swap_free+0xb6>
mov    -0x10(%rbp),%rdi
lea    -0x130(%rbp),%rdx
lea    0xe62(%rip),%rsi
lea    -0x28(%rbp),%rcx
call   1040 <fscanf@plt>
lea    -0x130(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11e8 <swap_free+0x88>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1211 <swap_free+0xb1>
lea    -0x130(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    120c <swap_free+0xac>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1211 <swap_free+0xb1>
jmp    1186 <swap_free+0x26>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rdi
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  0xdcf(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdf3(%rip),%rsi
call   1080 <sprintf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_free>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rdi,0x8(%rsp)
lea    0xe9b(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11cd <swap_free+0x7d>
mov    %rbx,%rdi
call   1030 <fclose@plt>
cvtsi2sdq 0x10(%rsp),%xmm0
mulsd  0xe61(%rip),%xmm0
cvtsi2sdq 0x18(%rsp),%xmm1
divsd  %xmm1,%xmm0
lea    0xe88(%rip),%rsi
mov    0x8(%rsp),%rdi
call   1070 <sprintf@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe44(%rip),%r15
lea    0x20(%rsp),%r12
mov    %rsp,%r13
movabs $0x61746f5470617753,%r14
6f 74 61
movabs $0x3a6c61746f5470,%rbp
jmp    1219 <swap_free+0xc9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsp),%rax
mov    %rax,0x18(%rsp)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    1188 <swap_free+0x38>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1040 <fscanf@plt>
mov    0x20(%rsp),%rax
xor    %r14,%rax
mov    0x23(%rsp),%rcx
xor    %rbp,%rcx
or     %rax,%rcx
je     1200 <swap_free+0xb0>
mov    0x20(%rsp),%rax
movabs $0x6565724670617753,%rcx
72 65 65
xor    %rcx,%rax
movzwl 0x28(%rsp),%ecx
xor    $0x3a,%rcx
or     %rax,%rcx
jne    1209 <swap_free+0xb9>
mov    (%rsp),%rax
mov    %rax,0x10(%rsp)
jmp    1209 <swap_free+0xb9>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"%s %ld %*s\0A\00"
@.str.3 = [11 x i8] c"SwapTotal:\00"
@.str.4 = [10 x i8] c"SwapFree:\00"
@.str.5 = [5 x i8] c"%.1f\00"
define void @swap_free(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca [256 x i8]
store i8* %0, i8** %2
%8 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
br label %9
9: ; preds = %30, %1
%10 = load i32*, i32** %3
%11 = call i32 @feof(i32* %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %31
14: ; preds = %9
%15 = load i32*, i32** %3
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%17 = call i32 @fscanf(i32* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %16, i64* %6)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%19 = call i32 @strcmp(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp ne i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %14
%22 = load i64, i64* %6
store i64 %22, i64* %4
br label %30
23: ; preds = %14
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = load i64, i64* %6
store i64 %28, i64* %5
br label %29
29: ; preds = %27, %23
br label %30
30: ; preds = %29, %21
br label %9
31: ; preds = %9
%32 = load i32*, i32** %3
%33 = call i32 @fclose(i32* %32)
%34 = load i8*, i8** %2
%35 = load i64, i64* %5
%36 = sitofp i64 %35 to double
%37 = fmul double 1.000000e+02, %36
%38 = load i64, i64* %4
%39 = sitofp i64 %38 to double
%40 = fdiv double %37, %39
%41 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), double %40)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"%s %ld %*s\0A\00"
@.str.3 = [11 x i8] c"SwapTotal:\00"
@.str.4 = [10 x i8] c"SwapFree:\00"
@.str.5 = [5 x i8] c"%.1f\00"
define void @swap_free(i8* nocapture writeonly %0) {
%2 = alloca i64
%3 = alloca [256 x i8]
%4 = bitcast i64* %2 to i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @feof(i32* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %1, %22
%10 = phi i64 [ %24, %22 ], [ undef, %1 ]
%11 = phi i64 [ %23, %22 ], [ undef, %1 ]
%12 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %5, i64* %2)
%13 = call i32 @bcmp(i8* dereferenceable(11) %5, i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 11)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = load i64, i64* %2
br label %22
17: ; preds = %9
%18 = call i32 @bcmp(i8* dereferenceable(10) %5, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i64 10)
%19 = icmp eq i32 %18, 0
%20 = load i64, i64* %2
%21 = select i1 %19, i64 %20, i64 %10
br label %22
22: ; preds = %17, %15
%23 = phi i64 [ %16, %15 ], [ %11, %17 ]
%24 = phi i64 [ %10, %15 ], [ %21, %17 ]
%25 = call i32 @feof(i32* %6)
%26 = icmp eq i32 %25, 0
br i1 %26, label %9, label %27
27: ; preds = %22, %1
%28 = phi i64 [ undef, %1 ], [ %23, %22 ]
%29 = phi i64 [ undef, %1 ], [ %24, %22 ]
%30 = call i32 @fclose(i32* %6)
%31 = sitofp i64 %29 to double
%32 = fmul double %31, 1.000000e+02
%33 = sitofp i64 %28 to double
%34 = fdiv double %32, %33
%35 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), double %34)
ret void
}