#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 */
char const *bprintf(char *, int);
scalar_t__ get_swap_info(long *, long *, long *);
const char *swap_perc(void) {
  long total, free, cached;
  if (get_swap_info(&total, &free, &cached) || total == 0) {
    return NULL;
  }
  return bprintf("%d", 100 * (total - free - cached) / total);
}


x86 assembly (clang, -O0):
<swap_perc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <get_swap_info@plt>
cmp    $0x0,%rax
jne    114e <swap_perc+0x2e>
cmpq   $0x0,-0x10(%rbp)
jne    115b <swap_perc+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    1183 <swap_perc+0x63>
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
imul   $0x64,%rax,%rax
cqto
idivq  -0x10(%rbp)
mov    %eax,%esi
lea    0xe86(%rip),%rdi
call   1030 <bprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_perc>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <get_swap_info@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1185 <swap_perc+0x65>
mov    0x10(%rsp),%rcx
test   %rcx,%rcx
je     1185 <swap_perc+0x65>
mov    0x8(%rsp),%rax
add    (%rsp),%rax
mov    %rcx,%rdx
sub    %rax,%rdx
imul   $0x64,%rdx,%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1173 <swap_perc+0x53>
cqto
idiv   %rcx
mov    %rax,%rsi
jmp    1179 <swap_perc+0x59>
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
lea    0xe80(%rip),%rdi
call   1030 <bprintf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i8* @swap_perc() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = call i64 @get_swap_info(i64* %2, i64* %3, i64* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = load i64, i64* %2
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %7, %0
store i8* null, i8** %1
br label %22
11: ; preds = %7
%12 = load i64, i64* %2
%13 = load i64, i64* %3
%14 = sub nsw i64 %12, %13
%15 = load i64, i64* %4
%16 = sub nsw i64 %14, %15
%17 = mul nsw i64 100, %16
%18 = load i64, i64* %2
%19 = sdiv i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
store i8* %21, i8** %1
br label %22
22: ; preds = %11, %10
%23 = load i8*, i8** %1
ret i8* %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i8* @swap_perc() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %1 to i8*
%5 = bitcast i64* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = call i64 @get_swap_info(i64* %1, i64* %2, i64* %3)
%8 = icmp ne i64 %7, 0
%9 = load i64, i64* %1
%10 = icmp eq i64 %9, 0
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %21, label %12
12: ; preds = %0
%13 = load i64, i64* %2
%14 = load i64, i64* %3
%15 = add i64 %13, %14
%16 = sub i64 %9, %15
%17 = mul nsw i64 %16, 100
%18 = sdiv i64 %17, %9
%19 = trunc i64 %18 to i32
%20 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %0, %12
%22 = phi i8* [ %20, %12 ], [ null, %0 ]
ret i8* %22
}