#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 uint32_t;
typedef int /*<<< orphan*/ dummy;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int fseeko(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
size_t my_fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int write_front_and_end_padding_bytes_to_stream(uint32_t dummy, FILE *fp) {
  size_t nwritten = my_fwrite(&dummy, sizeof(dummy), 1, fp);
  if (nwritten != 1) {
    fprintf(stderr,
            "Error: While writing (front) padding bytes for field with %u "
            "bytes. Managed to only write %zu bytes instead of 4\n",
            dummy, nwritten);
    return EXIT_FAILURE;
  }
  int status = fseeko(fp, dummy, SEEK_CUR);
  if (status < 0) {
    fprintf(stderr,
            "Error: While seeking file pointer to disk location. Offset was to "
            "be %u bytes\n",
            dummy);
    perror(NULL);
    return EXIT_FAILURE;
  }
  nwritten = my_fwrite(&dummy, sizeof(dummy), 1, fp);
  if (nwritten != 1) {
    fprintf(stderr,
            "Error: While writing (end) padding bytes for field with %u bytes. "
            "Managed to only write %zu bytes instead of 4\n",
            dummy, nwritten);
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<write_front_and_end_padding_bytes_to_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <my_fwrite@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
je     11a4 <write_front_and_end_padding_bytes_to_stream+0x64>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <write_front_and_end_padding_bytes_to_stream+0x11b>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
call   1050 <fseeko@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11fa <write_front_and_end_padding_bytes_to_stream+0xba>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe99(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <perror@plt>
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <write_front_and_end_padding_bytes_to_stream+0x11b>
mov    -0x10(%rbp),%rcx
lea    -0x8(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <my_fwrite@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
je     124f <write_front_and_end_padding_bytes_to_stream+0x10f>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe8a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <write_front_and_end_padding_bytes_to_stream+0x11b>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_front_and_end_padding_bytes_to_stream>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <my_fwrite@plt>
cmp    $0x1,%rax
jne    11a8 <write_front_and_end_padding_bytes_to_stream+0x68>
mov    0xc(%rsp),%esi
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1050 <fseeko@plt>
test   %eax,%eax
js     11eb <write_front_and_end_padding_bytes_to_stream+0xab>
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <my_fwrite@plt>
cmp    $0x1,%rax
jne    11be <write_front_and_end_padding_bytes_to_stream+0x7e>
mov    0x2e22(%rip),%rax
jmp    11e3 <write_front_and_end_padding_bytes_to_stream+0xa3>
mov    0x2e29(%rip),%rcx
mov    (%rcx),%edi
mov    0xc(%rsp),%edx
lea    0xe44(%rip),%rsi
jmp    11d2 <write_front_and_end_padding_bytes_to_stream+0x92>
mov    0x2e13(%rip),%rcx
mov    (%rcx),%edi
mov    0xc(%rsp),%edx
lea    0xeef(%rip),%rsi
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%edx
lea    0xe73(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1060 <perror@plt>
jmp    11dc <write_front_and_end_padding_bytes_to_stream+0x9c>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [114 x i8] c"Error: While writing (front) padding bytes for field with %u bytes. Managed to only write %zu bytes instead of 4\0A\00"
@EXIT_FAILURE = global i32 0
@SEEK_CUR = global i32 0
@.str.1 = [79 x i8] c"Error: While seeking file pointer to disk location. Offset was to be %u bytes\0A\00"
@.str.2 = [112 x i8] c"Error: While writing (end) padding bytes for field with %u bytes. Managed to only write %zu bytes instead of 4\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @write_front_and_end_padding_bytes_to_stream(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%8 = load i32*, i32** %5
%9 = call i64 @my_fwrite(i32* %4, i32 4, i32 1, i32* %8)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = icmp ne i64 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i32, i32* %4
%15 = load i64, i64* %6
%16 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str, i64 0, i64 0), i32 %14, i64 %15)
%17 = load i32, i32* @EXIT_FAILURE
store i32 %17, i32* %3
br label %44
18: ; preds = %2
%19 = load i32*, i32** %5
%20 = load i32, i32* %4
%21 = load i32, i32* @SEEK_CUR
%22 = call i32 @fseeko(i32* %19, i32 %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i32, i32* %4
%28 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @perror(i32* null)
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %44
31: ; preds = %18
%32 = load i32*, i32** %5
%33 = call i64 @my_fwrite(i32* %4, i32 4, i32 1, i32* %32)
store i64 %33, i64* %6
%34 = load i64, i64* %6
%35 = icmp ne i64 %34, 1
br i1 %35, label %36, label %42
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = load i32, i32* %4
%39 = load i64, i64* %6
%40 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.2, i64 0, i64 0), i32 %38, i64 %39)
%41 = load i32, i32* @EXIT_FAILURE
store i32 %41, i32* %3
br label %44
42: ; preds = %31
%43 = load i32, i32* @EXIT_SUCCESS
store i32 %43, i32* %3
br label %44
44: ; preds = %42, %36, %25, %12
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [114 x i8] c"Error: While writing (front) padding bytes for field with %u bytes. Managed to only write %zu bytes instead of 4\0A\00"
@EXIT_FAILURE = global i32 0
@SEEK_CUR = global i32 0
@.str.1 = [79 x i8] c"Error: While seeking file pointer to disk location. Offset was to be %u bytes\0A\00"
@.str.2 = [112 x i8] c"Error: While writing (end) padding bytes for field with %u bytes. Managed to only write %zu bytes instead of 4\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @write_front_and_end_padding_bytes_to_stream(i32 %0, i32* %1) {
%3 = alloca i32
store i32 %0, i32* %3
%4 = call i64 @my_fwrite(i32* %3, i32 4, i32 1, i32* %1)
%5 = icmp eq i64 %4, 1
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i32, i32* %3
%9 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([114 x i8], [114 x i8]* @.str, i64 0, i64 0), i32 %8, i64 %4)
br label %27
10: ; preds = %2
%11 = load i32, i32* %3
%12 = load i32, i32* @SEEK_CUR
%13 = call i32 @fseeko(i32* %1, i32 %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i32, i32* %3
%18 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32 @perror(i32* null)
br label %27
20: ; preds = %10
%21 = call i64 @my_fwrite(i32* %3, i32 4, i32 1, i32* %1)
%22 = icmp eq i64 %21, 1
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = load i32, i32* %3
%26 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.2, i64 0, i64 0), i32 %25, i64 %21)
br label %27
27: ; preds = %15, %23, %20, %6
%28 = phi i32* [ @EXIT_FAILURE, %6 ], [ @EXIT_FAILURE, %15 ], [ @EXIT_FAILURE, %23 ], [ @EXIT_SUCCESS, %20 ]
%29 = load i32, i32* %28
ret i32 %29
}