#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*/ uint8_t;
struct csum_state {
  int dummy;
};
typedef size_t len;
typedef size_t align;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int write_out_data(int /*<<< orphan*/ *, int /*<<< orphan*/ *, size_t,
                   struct csum_state *);
int write_out_padding(int /*<<< orphan*/ *, size_t, int, struct csum_state *);
int write_out_data_align(FILE *outfile, uint8_t *data, size_t len, size_t align,
                         struct csum_state *css) {
  size_t padlen;
  int res;
  res = write_out_data(outfile, data, len, css);
  if (res)
    return res;
  padlen = (((len) + ((align)-1)) & ~((align)-1)) - len;
  res = write_out_padding(outfile, padlen, 0xFF, css);
  return res;
}


x86 assembly (clang, -O0):
<write_out_data_align>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1030 <write_out_data@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1169 <write_out_data_align+0x49>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ae <write_out_data_align+0x8e>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
add    %rcx,%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
xor    $0xffffffffffffffff,%rcx
and    %rcx,%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    $0xff,%edx
call   1040 <write_out_padding@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_out_data_align>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%rbx
mov    %rdx,%r12
mov    %rdi,%r15
mov    %r8,%rcx
call   1030 <write_out_data@plt>
test   %eax,%eax
je     114c <write_out_data_align+0x2c>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    (%r12,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
neg    %rbx
and    %rax,%rbx
sub    %r12,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0xff,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <write_out_padding@plt>

LLVM IR (-O0):
%struct.csum_state = type { i32 }
define i32 @write_out_data_align(i32* %0, i32* %1, i64 %2, i64 %3, %struct.csum_state* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca %struct.csum_state*
%12 = alloca i64
%13 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i64 %2, i64* %9
store i64 %3, i64* %10
store %struct.csum_state* %4, %struct.csum_state** %11
%14 = load i32*, i32** %7
%15 = load i32*, i32** %8
%16 = load i64, i64* %9
%17 = load %struct.csum_state*, %struct.csum_state** %11
%18 = call i32 @write_out_data(i32* %14, i32* %15, i64 %16, %struct.csum_state* %17)
store i32 %18, i32* %13
%19 = load i32, i32* %13
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %5
%22 = load i32, i32* %13
store i32 %22, i32* %6
br label %39
23: ; preds = %5
%24 = load i64, i64* %9
%25 = load i64, i64* %10
%26 = sub i64 %25, 1
%27 = add i64 %24, %26
%28 = load i64, i64* %10
%29 = sub i64 %28, 1
%30 = xor i64 %29, -1
%31 = and i64 %27, %30
%32 = load i64, i64* %9
%33 = sub i64 %31, %32
store i64 %33, i64* %12
%34 = load i32*, i32** %7
%35 = load i64, i64* %12
%36 = load %struct.csum_state*, %struct.csum_state** %11
%37 = call i32 @write_out_padding(i32* %34, i64 %35, i32 255, %struct.csum_state* %36)
store i32 %37, i32* %13
%38 = load i32, i32* %13
store i32 %38, i32* %6
br label %39
39: ; preds = %23, %21
%40 = load i32, i32* %6
ret i32 %40
}

LLVM IR (-O2):
%struct.csum_state = type { i32 }
define i32 @write_out_data_align(i32* %0, i32* %1, i64 %2, i64 %3, %struct.csum_state* %4) {
%6 = tail call i32 @write_out_data(i32* %0, i32* %1, i64 %2, %struct.csum_state* %4)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = add i64 %2, -1
%10 = add i64 %9, %3
%11 = sub i64 0, %3
%12 = and i64 %10, %11
%13 = sub i64 %12, %2
%14 = tail call i32 @write_out_padding(i32* %0, i64 %13, i32 255, %struct.csum_state* %4)
br label %15
15: ; preds = %5, %8
%16 = phi i32 [ %14, %8 ], [ %6, %5 ]
ret i32 %16
}