#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 MS_ASYNC;
int MS_SYNC;
int msync(void *, size_t, int);
size_t pageAlignLen(void *, size_t);
void *pageAlignStart(void *);
int sasMsyncWrite(void *startAddr, size_t size, int asyncBool) {
  int flags;
  void *alignAddr = pageAlignStart(startAddr);
  size_t alignSize = pageAlignLen(startAddr, size);
  if (asyncBool)
    flags = (MS_ASYNC);
  else
    flags = (MS_SYNC);
  return msync(alignAddr, alignSize, flags);
}


x86 assembly (clang, -O0):
<sasMsyncWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <pageAlignStart@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <pageAlignLen@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117c <sasMsyncWrite+0x4c>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    1188 <sasMsyncWrite+0x58>
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <msync@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sasMsyncWrite>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1030 <pageAlignStart@plt>
mov    %rax,%r14
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <pageAlignLen@plt>
test   %r15d,%r15d
jne    1161 <sasMsyncWrite+0x31>
mov    0x2e79(%rip),%rcx
jmp    1168 <sasMsyncWrite+0x38>
mov    0x2e80(%rip),%rcx
mov    (%rcx),%edx
mov    %r14,%rdi
mov    %rax,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <msync@plt>

LLVM IR (-O0):
@MS_ASYNC = global i32 0
@MS_SYNC = global i32 0
define i32 @sasMsyncWrite(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
%11 = call i8* @pageAlignStart(i8* %10)
store i8* %11, i8** %8
%12 = load i8*, i8** %4
%13 = load i64, i64* %5
%14 = call i64 @pageAlignLen(i8* %12, i64 %13)
store i64 %14, i64* %9
%15 = load i32, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = load i32, i32* @MS_ASYNC
store i32 %18, i32* %7
br label %21
19: ; preds = %3
%20 = load i32, i32* @MS_SYNC
store i32 %20, i32* %7
br label %21
21: ; preds = %19, %17
%22 = load i8*, i8** %8
%23 = load i64, i64* %9
%24 = load i32, i32* %7
%25 = call i32 @msync(i8* %22, i64 %23, i32 %24)
ret i32 %25
}

LLVM IR (-O2):
@MS_ASYNC = global i32 0
@MS_SYNC = global i32 0
define i32 @sasMsyncWrite(i8* %0, i64 %1, i32 %2) {
%4 = tail call i8* @pageAlignStart(i8* %0)
%5 = tail call i64 @pageAlignLen(i8* %0, i64 %1)
%6 = icmp eq i32 %2, 0
%7 = load i32, i32* @MS_SYNC
%8 = load i32, i32* @MS_ASYNC
%9 = select i1 %6, i32 %7, i32 %8
%10 = tail call i32 @msync(i8* %4, i64 %5, i32 %9)
ret i32 %10
}