#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*/ put_byte_seek(int /*<<< orphan*/, long,
                                 int /*<<< orphan*/ *);
long pad(long current_offset, long pad_amount, FILE *outfile) {
  long new_offset = (current_offset + pad_amount - 1) / pad_amount * pad_amount;
  for (; current_offset < new_offset; current_offset++) {
    put_byte_seek(0, current_offset, outfile);
  }
  return new_offset;
}


x86 assembly (clang, -O0):
<pad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
sub    $0x1,%rax
cqto
idivq  -0x10(%rbp)
imul   -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    116d <pad+0x5d>
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %edi,%edi
call   1030 <put_byte_seek@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113f <pad+0x2f>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pad>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rdi,%r12
lea    (%rdi,%rsi,1),%r14
add    $0xffffffffffffffff,%r14
mov    %r14,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     113f <pad+0x2f>
mov    %r14,%rax
cqto
idiv   %rsi
mov    %rdx,%rbx
jmp    1148 <pad+0x38>
mov    %r14d,%eax
xor    %edx,%edx
div    %esi
mov    %edx,%ebx
sub    %rbx,%r14
cmp    %r12,%r14
jle    1177 <pad+0x67>
not    %rbx
add    %rsi,%rbx
cs nopw 0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <put_byte_seek@plt>
add    $0x1,%r12
add    $0xffffffffffffffff,%rbx
jne    1160 <pad+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @pad(i64 %0, i64 %1, i32* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
store i32* %2, i32** %6
%8 = load i64, i64* %4
%9 = load i64, i64* %5
%10 = add nsw i64 %8, %9
%11 = sub nsw i64 %10, 1
%12 = load i64, i64* %5
%13 = sdiv i64 %11, %12
%14 = load i64, i64* %5
%15 = mul nsw i64 %13, %14
store i64 %15, i64* %7
br label %16
16: ; preds = %24, %3
%17 = load i64, i64* %4
%18 = load i64, i64* %7
%19 = icmp slt i64 %17, %18
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = load i64, i64* %4
%22 = load i32*, i32** %6
%23 = call i32 @put_byte_seek(i32 0, i64 %21, i32* %22)
br label %24
24: ; preds = %20
%25 = load i64, i64* %4
%26 = add nsw i64 %25, 1
store i64 %26, i64* %4
br label %16
27: ; preds = %16
%28 = load i64, i64* %7
ret i64 %28
}

LLVM IR (-O2):
define i64 @pad(i64 %0, i64 %1, i32* %2) {
%4 = add i64 %0, -1
%5 = add i64 %4, %1
%6 = srem i64 %5, %1
%7 = sub i64 %5, %6
%8 = icmp sgt i64 %7, %0
br i1 %8, label %9, label %14
9: ; preds = %3, %9
%10 = phi i64 [ %12, %9 ], [ %0, %3 ]
%11 = tail call i32 @put_byte_seek(i32 0, i64 %10, i32* %2)
%12 = add i64 %10, 1
%13 = icmp eq i64 %12, %7
br i1 %13, label %14, label %9
14: ; preds = %9, %3
ret i64 %7
}