#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 long off_t;

/* Variables and functions */
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ log_failed_assert(char *, int, char *);
long sysconf(int /*<<< orphan*/);
off_t mmap_align_offset(off_t start) {
  static long pagesize = 0;
  if (0 == pagesize) {
    pagesize = sysconf(_SC_PAGESIZE);
    do {
      if (!(pagesize < (512 * 1024)))
        log_failed_assert(
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/PatchyFog/lighttpd1.4-mbedtls/refs/"
            "heads/master/src/network_write_mmap.c",
            21,
            "assertion failed: "
            "pagesize < MMAP_CHUNK_SIZE");
    } while (0);
  }
  do {
    if (!(start >= (start % pagesize)))
      log_failed_assert(
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/PatchyFog/lighttpd1.4-mbedtls/refs/heads/"
          "master/src/network_write_mmap.c",
          23,
          "assertion failed: "
          "start >= (start % pagesize)");
  } while (0);
  return start - (start % pagesize);
}


x86 assembly (clang, -O0):
<mmap_align_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
cmp    0x2f03(%rip),%rax
jne    1183 <mmap_align_offset+0x63>
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,0x2ee8(%rip)
cmpq   $0x80000,0x2edd(%rip)
jl     1179 <mmap_align_offset+0x59>
lea    0xe98(%rip),%rdi
mov    $0x15,%esi
lea    0xf2f(%rip),%rdx
call   1030 <log_failed_assert@plt>
jmp    117e <mmap_align_offset+0x5e>
jmp    1183 <mmap_align_offset+0x63>
jmp    1188 <mmap_align_offset+0x68>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  0x2e9b(%rip)
mov    -0x10(%rbp),%rax
cmp    %rdx,%rax
jge    11c2 <mmap_align_offset+0xa2>
lea    0xe4f(%rip),%rdi
mov    $0x17,%esi
lea    0xf13(%rip),%rdx
call   1030 <log_failed_assert@plt>
jmp    11c7 <mmap_align_offset+0xa7>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  0x2e5c(%rip)
mov    -0x18(%rbp),%rax
sub    %rdx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmap_align_offset>:
push   %rbx
mov    %rdi,%rbx
mov    0x2f0d(%rip),%rcx
test   %rcx,%rcx
jne    116f <mmap_align_offset+0x4f>
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
call   1040 <sysconf@plt>
mov    %rax,%rcx
mov    %rax,0x2ef0(%rip)
cmp    $0x80000,%rax
jl     116f <mmap_align_offset+0x4f>
lea    0xea9(%rip),%rdi
lea    0xf45(%rip),%rdx
mov    $0x15,%esi
call   1030 <log_failed_assert@plt>
mov    0x2ec9(%rip),%rcx
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     118a <mmap_align_offset+0x6a>
mov    %rbx,%rax
cqto
idiv   %rcx
cmp    %rbx,%rdx
jg     1195 <mmap_align_offset+0x75>
jmp    11d0 <mmap_align_offset+0xb0>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
cmp    %rbx,%rdx
jle    11d0 <mmap_align_offset+0xb0>
lea    0xe64(%rip),%rdi
lea    0xf2d(%rip),%rdx
mov    $0x17,%esi
call   1030 <log_failed_assert@plt>
mov    0x2e84(%rip),%rcx
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11ca <mmap_align_offset+0xaa>
mov    %rbx,%rax
cqto
idiv   %rcx
jmp    11d0 <mmap_align_offset+0xb0>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
sub    %rdx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@mmap_align_offset.pagesize = internal global i64 0
@_SC_PAGESIZE = global i32 0
@.str = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/PatchyFog/lighttpd1.4-mbedtls/refs/heads/master/src/network_write_mmap.c\00"
@.str.1 = [45 x i8] c"assertion failed: pagesize < MMAP_CHUNK_SIZE\00"
@.str.2 = [46 x i8] c"assertion failed: start >= (start % pagesize)\00"
define i64 @mmap_align_offset(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* @mmap_align_offset.pagesize
%4 = icmp eq i64 0, %3
br i1 %4, label %5, label %15
5: ; preds = %1
%6 = load i32, i32* @_SC_PAGESIZE
%7 = call i64 @sysconf(i32 %6)
store i64 %7, i64* @mmap_align_offset.pagesize
br label %8
8: ; preds = %5
%9 = load i64, i64* @mmap_align_offset.pagesize
%10 = icmp slt i64 %9, 524288
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 @log_failed_assert(i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
br label %14
14: ; preds = %13
br label %15
15: ; preds = %14, %1
br label %16
16: ; preds = %15
%17 = load i64, i64* %2
%18 = load i64, i64* %2
%19 = load i64, i64* @mmap_align_offset.pagesize
%20 = srem i64 %18, %19
%21 = icmp sge i64 %17, %20
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = call i32 @log_failed_assert(i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
br label %25
25: ; preds = %24
%26 = load i64, i64* %2
%27 = load i64, i64* %2
%28 = load i64, i64* @mmap_align_offset.pagesize
%29 = srem i64 %27, %28
%30 = sub nsw i64 %26, %29
ret i64 %30
}

LLVM IR (-O2):
@mmap_align_offset.pagesize = internal unnamed_addr global i64 0
@_SC_PAGESIZE = global i32 0
@.str = [163 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/PatchyFog/lighttpd1.4-mbedtls/refs/heads/master/src/network_write_mmap.c\00"
@.str.1 = [45 x i8] c"assertion failed: pagesize < MMAP_CHUNK_SIZE\00"
@.str.2 = [46 x i8] c"assertion failed: start >= (start % pagesize)\00"
define i64 @mmap_align_offset(i64 %0) {
%2 = load i64, i64* @mmap_align_offset.pagesize
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = load i32, i32* @_SC_PAGESIZE
%6 = tail call i64 @sysconf(i32 %5)
store i64 %6, i64* @mmap_align_offset.pagesize
%7 = icmp slt i64 %6, 524288
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = tail call i32 @log_failed_assert(i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%10 = load i64, i64* @mmap_align_offset.pagesize
br label %11
11: ; preds = %1, %4, %8
%12 = phi i64 [ %2, %1 ], [ %6, %4 ], [ %10, %8 ]
%13 = srem i64 %0, %12
%14 = icmp sgt i64 %13, %0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = tail call i32 @log_failed_assert(i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%17 = load i64, i64* @mmap_align_offset.pagesize
%18 = srem i64 %0, %17
br label %19
19: ; preds = %11, %15
%20 = phi i64 [ %13, %11 ], [ %18, %15 ]
%21 = sub nsw i64 %0, %20
ret i64 %21
}