#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*/ uint64_t;
struct stat {
  size_t st_size;
};
typedef size_t off_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ msg_Err(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ msg_Warn(int /*<<< orphan*/ *, char *, ...);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ truncate(char const *, size_t);
void CheckFileSizes(const char *psz_file, const char *psz_aux_file,
                    size_t i_payload_size) {
  struct stat st;
  off_t i_file_packets, i_aux_packets;
  if (stat(psz_file, &st) < 0)
    i_file_packets = 0;
  else {
    i_file_packets = st.st_size / i_payload_size;
    if (st.st_size % i_payload_size) {
      msg_Warn(NULL, "file size is not a multiple of %jd, truncating",
               i_payload_size);
      if (truncate(psz_file, i_file_packets * i_payload_size) < 0)
        msg_Err(NULL, "truncate failed (%s)", strerror(errno));
    }
  }
  if (stat(psz_aux_file, &st) < 0)
    i_aux_packets = 0;
  else {
    i_aux_packets = st.st_size / sizeof(uint64_t);
    if (st.st_size % sizeof(uint64_t)) {
      msg_Warn(NULL, "aux size is not a multiple of %jd, truncating",
               sizeof(uint64_t));
      if (truncate(psz_aux_file, i_aux_packets * sizeof(uint64_t)) < 0)
        msg_Err(NULL, "truncate failed (%s)", strerror(errno));
    }
  }
  if (i_file_packets < i_aux_packets) {
    msg_Warn(NULL, "truncating aux file");
    if (truncate(psz_aux_file, i_file_packets * sizeof(uint64_t)) < 0)
      msg_Err(NULL, "truncate failed (%s)", strerror(errno));
  } else if (i_aux_packets < i_file_packets) {
    msg_Warn(NULL, "truncating file");
    if (truncate(psz_file, i_aux_packets * i_payload_size) < 0)
      msg_Err(NULL, "truncate failed (%s)", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<CheckFileSizes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    1188 <CheckFileSizes+0x38>
movq   $0x0,-0x28(%rbp)
jmp    120a <CheckFileSizes+0xba>
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
cmp    $0x0,%rdx
je     1205 <CheckFileSizes+0xb5>
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1060 <msg_Warn@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
imul   -0x18(%rbp),%rsi
call   1050 <truncate@plt>
cmp    $0x0,%rax
jge    1200 <CheckFileSizes+0xb0>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%edi
lea    0xe34(%rip),%rsi
call   1030 <msg_Err@plt>
jmp    1205 <CheckFileSizes+0xb5>
jmp    120a <CheckFileSizes+0xba>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jge    122e <CheckFileSizes+0xde>
movq   $0x0,-0x30(%rbp)
jmp    12a8 <CheckFileSizes+0x158>
mov    -0x20(%rbp),%rax
shr    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
je     12a3 <CheckFileSizes+0x153>
xor    %eax,%eax
mov    %eax,%edi
lea    0xded(%rip),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1060 <msg_Warn@plt>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
shl    $0x2,%rsi
call   1050 <truncate@plt>
cmp    $0x0,%rax
jge    129e <CheckFileSizes+0x14e>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%edi
lea    0xd96(%rip),%rsi
call   1030 <msg_Err@plt>
jmp    12a3 <CheckFileSizes+0x153>
jmp    12a8 <CheckFileSizes+0x158>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1308 <CheckFileSizes+0x1b8>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1060 <msg_Warn@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
shl    $0x2,%rsi
call   1050 <truncate@plt>
cmp    $0x0,%rax
jge    1303 <CheckFileSizes+0x1b3>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%edi
lea    0xd31(%rip),%rsi
call   1030 <msg_Err@plt>
jmp    136e <CheckFileSizes+0x21e>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1369 <CheckFileSizes+0x219>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   1060 <msg_Warn@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
imul   -0x18(%rbp),%rsi
call   1050 <truncate@plt>
cmp    $0x0,%rax
jge    1364 <CheckFileSizes+0x214>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%edi
lea    0xcd0(%rip),%rsi
call   1030 <msg_Err@plt>
jmp    1369 <CheckFileSizes+0x219>
jmp    136e <CheckFileSizes+0x21e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckFileSizes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%rsi
call   1040 <stat@plt>
test   %rax,%rax
js     1190 <CheckFileSizes+0x40>
mov    (%rsp),%rax
mov    %rax,%rcx
or     %r12,%rcx
shr    $0x20,%rcx
je     1195 <CheckFileSizes+0x45>
xor    %edx,%edx
div    %r12
mov    %rax,%r13
test   %rdx,%rdx
jne    11a2 <CheckFileSizes+0x52>
jmp    11e7 <CheckFileSizes+0x97>
xor    %r13d,%r13d
jmp    11e7 <CheckFileSizes+0x97>
xor    %edx,%edx
div    %r12d
mov    %eax,%r13d
test   %rdx,%rdx
je     11e7 <CheckFileSizes+0x97>
lea    0xe57(%rip),%rsi
xor    %edi,%edi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <msg_Warn@plt>
mov    %r13,%rsi
imul   %r12,%rsi
mov    %r14,%rdi
call   1050 <truncate@plt>
test   %rax,%rax
jns    11e7 <CheckFileSizes+0x97>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe51(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
call   1030 <msg_Err@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1040 <stat@plt>
test   %rax,%rax
js     1270 <CheckFileSizes+0x120>
mov    (%rsp),%rbp
mov    %rbp,%rbx
shr    $0x2,%rbx
test   $0x3,%bpl
je     124f <CheckFileSizes+0xff>
lea    0xe35(%rip),%rsi
mov    $0x4,%edx
xor    %edi,%edi
xor    %eax,%eax
call   1060 <msg_Warn@plt>
and    $0xfffffffffffffffc,%rbp
mov    %r15,%rdi
mov    %rbp,%rsi
call   1050 <truncate@plt>
test   %rax,%rax
jns    124f <CheckFileSizes+0xff>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xde9(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
call   1030 <msg_Err@plt>
cmp    %rbx,%r13
jae    1277 <CheckFileSizes+0x127>
lea    0xe17(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1060 <msg_Warn@plt>
shl    $0x2,%r13
mov    %r15,%rdi
mov    %r13,%rsi
jmp    1293 <CheckFileSizes+0x143>
xor    %ebx,%ebx
cmp    %rbx,%r13
jb     1254 <CheckFileSizes+0x104>
jbe    12bb <CheckFileSizes+0x16b>
lea    0xe06(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1060 <msg_Warn@plt>
imul   %r12,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <truncate@plt>
test   %rax,%rax
jns    12bb <CheckFileSizes+0x16b>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xd7d(%rip),%rsi
xor    %edi,%edi
mov    %eax,%edx
call   1030 <msg_Err@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [47 x i8] c"file size is not a multiple of %jd, truncating\00"
@.str.1 = [21 x i8] c"truncate failed (%s)\00"
@errno = global i32 0
@.str.2 = [46 x i8] c"aux size is not a multiple of %jd, truncating\00"
@.str.3 = [20 x i8] c"truncating aux file\00"
@.str.4 = [16 x i8] c"truncating file\00"
define void @CheckFileSizes(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.stat
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %4
%11 = call i64 @stat(i8* %10, %struct.stat* %7)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i64 0, i64* %8
br label %39
14: ; preds = %3
%15 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* %6
%18 = udiv i64 %16, %17
store i64 %18, i64* %8
%19 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%20 = load i64, i64* %19
%21 = load i64, i64* %6
%22 = urem i64 %20, %21
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %14
%25 = load i64, i64* %6
%26 = call i32 (i32*, i8*, ...) @msg_Warn(i32* null, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 %25)
%27 = load i8*, i8** %4
%28 = load i64, i64* %8
%29 = load i64, i64* %6
%30 = mul i64 %28, %29
%31 = call i64 @truncate(i8* %27, i64 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %24
%34 = load i32, i32* @errno
%35 = call i32 @strerror(i32 %34)
%36 = call i32 @msg_Err(i32* null, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %33, %24
br label %38
38: ; preds = %37, %14
br label %39
39: ; preds = %38, %13
%40 = load i8*, i8** %5
%41 = call i64 @stat(i8* %40, %struct.stat* %7)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
store i64 0, i64* %9
br label %65
44: ; preds = %39
%45 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%46 = load i64, i64* %45
%47 = udiv i64 %46, 4
store i64 %47, i64* %9
%48 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%49 = load i64, i64* %48
%50 = urem i64 %49, 4
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %64
52: ; preds = %44
%53 = call i32 (i32*, i8*, ...) @msg_Warn(i32* null, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 4)
%54 = load i8*, i8** %5
%55 = load i64, i64* %9
%56 = mul i64 %55, 4
%57 = call i64 @truncate(i8* %54, i64 %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %52
%60 = load i32, i32* @errno
%61 = call i32 @strerror(i32 %60)
%62 = call i32 @msg_Err(i32* null, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %59, %52
br label %64
64: ; preds = %63, %44
br label %65
65: ; preds = %64, %43
%66 = load i64, i64* %8
%67 = load i64, i64* %9
%68 = icmp ult i64 %66, %67
br i1 %68, label %69, label %81
69: ; preds = %65
%70 = call i32 (i32*, i8*, ...) @msg_Warn(i32* null, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%71 = load i8*, i8** %5
%72 = load i64, i64* %8
%73 = mul i64 %72, 4
%74 = call i64 @truncate(i8* %71, i64 %73)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %69
%77 = load i32, i32* @errno
%78 = call i32 @strerror(i32 %77)
%79 = call i32 @msg_Err(i32* null, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %78)
br label %80
80: ; preds = %76, %69
br label %99
81: ; preds = %65
%82 = load i64, i64* %9
%83 = load i64, i64* %8
%84 = icmp ult i64 %82, %83
br i1 %84, label %85, label %98
85: ; preds = %81
%86 = call i32 (i32*, i8*, ...) @msg_Warn(i32* null, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%87 = load i8*, i8** %4
%88 = load i64, i64* %9
%89 = load i64, i64* %6
%90 = mul i64 %88, %89
%91 = call i64 @truncate(i8* %87, i64 %90)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %97
93: ; preds = %85
%94 = load i32, i32* @errno
%95 = call i32 @strerror(i32 %94)
%96 = call i32 @msg_Err(i32* null, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %95)
br label %97
97: ; preds = %93, %85
br label %98
98: ; preds = %97, %81
br label %99
99: ; preds = %98, %80
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [47 x i8] c"file size is not a multiple of %jd, truncating\00"
@.str.1 = [21 x i8] c"truncate failed (%s)\00"
@errno = global i32 0
@.str.2 = [46 x i8] c"aux size is not a multiple of %jd, truncating\00"
@.str.3 = [20 x i8] c"truncating aux file\00"
@.str.4 = [16 x i8] c"truncating file\00"
define void @CheckFileSizes(i8* %0, i8* %1, i64 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i64 @stat(i8* %0, %struct.stat* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %3
%9 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%10 = load i64, i64* %9
%11 = udiv i64 %10, %2
%12 = urem i64 %10, %2
%13 = icmp eq i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %8
%15 = call i32 (i32*, i8*, ...) @msg_Warn(i32* null, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 %2)
%16 = mul i64 %11, %2
%17 = call i64 @truncate(i8* %0, i64 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 @msg_Err(i32* null, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %3, %8, %19, %14
%24 = phi i64 [ %11, %19 ], [ %11, %14 ], [ %11, %8 ], [ 0, %3 ]
%25 = call i64 @stat(i8* %1, %struct.stat* %4)
%26 = icmp slt i64 %25, 0
br i1 %26, label %42, label %27
27: ; preds = %23
%28 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%29 = load i64, i64* %28
%30 = lshr i64 %29, 2
%31 = and i64 %29, 3
%32 = icmp eq i64 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %27
%34 = call i32 (i32*, i8*, ...) @msg_Warn(i32* null, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i64 4)
%35 = and i64 %29, -4
%36 = call i64 @truncate(i8* %1, i64 %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i32, i32* @errno
%40 = call i32 @strerror(i32 %39)
%41 = call i32 @msg_Err(i32* null, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %23, %27, %38, %33
%43 = phi i64 [ %30, %38 ], [ %30, %33 ], [ %30, %27 ], [ 0, %23 ]
%44 = icmp ult i64 %24, %43
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = call i32 (i32*, i8*, ...) @msg_Warn(i32* null, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%47 = shl i64 %24, 2
%48 = call i64 @truncate(i8* %1, i64 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %57, label %61
50: ; preds = %42
%51 = icmp ult i64 %43, %24
br i1 %51, label %52, label %61
52: ; preds = %50
%53 = call i32 (i32*, i8*, ...) @msg_Warn(i32* null, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%54 = mul i64 %43, %2
%55 = call i64 @truncate(i8* %0, i64 %54)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %52, %45
%58 = load i32, i32* @errno
%59 = call i32 @strerror(i32 %58)
%60 = call i32 @msg_Err(i32* null, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %57, %50, %52, %45
ret void
}