#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 */
struct stat {
  long st_size;
};
struct DAPS {
  int dummy;
};
typedef long off_t;

/* Variables and functions */
void const *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ __ASSERT_VOID_CAST(int /*<<< orphan*/);
int barebox_linear_image(struct DAPS *, int, long);
int check_for_space(void *, long);
int check_for_valid_mbr(void const *, long);
int fill_daps(struct DAPS *, int, int, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fstat(int, struct stat *);
int /*<<< orphan*/ memcpy(void *, void const *, int);
void *mmap(int /*<<< orphan*/ *, long, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, long);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int store_pers_env_info(struct DAPS *, int, long);
int barebox_overlay_mbr(int fd_barebox, int fd_hd, long pers_sector_count) {
  const void *barebox_image;
  void *hd_image;
  int rc;
  struct stat sb;
  struct DAPS *embed;
  struct DAPS *indirect;
  off_t required_size;
  if (fstat(fd_barebox, &sb) == -1) {
    perror("fstat");
    return -1;
  }
  barebox_image = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd_barebox, 0);
  if (barebox_image == MAP_FAILED) {
    perror("mmap");
    return -1;
  }
  rc = check_for_valid_mbr(barebox_image, sb.st_size);
  if (rc != 0) {
    fprintf(stderr, "barebox image seems not valid: Bad MBR signature\n");
    goto on_error_hd;
  }
  required_size = sb.st_size + pers_sector_count * 512;
  hd_image =
      mmap(NULL, required_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_hd, 0);
  if (hd_image == MAP_FAILED) {
    perror("mmap");
    rc = -1;
    goto on_error_hd;
  }
  rc = check_for_space(hd_image, required_size);
  if (rc != 0)
    goto on_error_space;
  memcpy(hd_image, barebox_image, 446);
  memcpy(hd_image + ((pers_sector_count + 1) * 512), barebox_image + 512,
         sb.st_size - 512);
  embed = hd_image + 400;
  indirect = hd_image + ((pers_sector_count + 1) * 512);
  rc = fill_daps(embed, 1, 0x7A00, 0x0000, 1 + pers_sector_count);
  if (rc != 0)
    goto on_error_space;
  (__ASSERT_VOID_CAST(0));
  rc = barebox_linear_image(indirect, sb.st_size, pers_sector_count);
  if (rc != 0)
    goto on_error_space;
  rc = store_pers_env_info(embed, 1, pers_sector_count);
  if (rc != 0)
    goto on_error_space;
on_error_space:
  munmap(hd_image, required_size);
on_error_hd:
  munmap((void *)barebox_image, sb.st_size);
  return rc;
}


x86 assembly (clang, -O0):
<barebox_overlay_mbr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   10e0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    11ff <barebox_overlay_mbr+0x3f>
lea    0xe12(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1427 <barebox_overlay_mbr+0x267>
mov    -0x38(%rbp),%rsi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
mov    0x2dd5(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d8c(%rip),%rcx
cmp    (%rcx),%rax
jne    1255 <barebox_overlay_mbr+0x95>
lea    0xdc2(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1427 <barebox_overlay_mbr+0x267>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <check_for_valid_mbr@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1289 <barebox_overlay_mbr+0xc9>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1414 <barebox_overlay_mbr+0x254>
mov    -0x38(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x9,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rsi
mov    0x2d51(%rip),%rax
mov    (%rax),%edx
mov    0x2d18(%rip),%rax
or     (%rax),%edx
mov    0x2d2f(%rip),%rax
mov    (%rax),%ecx
mov    -0xc(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2ce6(%rip),%rcx
cmp    (%rcx),%rax
jne    12fb <barebox_overlay_mbr+0x13b>
lea    0xd1c(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    1414 <barebox_overlay_mbr+0x254>
mov    -0x28(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1070 <check_for_space@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     131a <barebox_overlay_mbr+0x15a>
jmp    1407 <barebox_overlay_mbr+0x247>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1be,%edx
call   1090 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
add    $0x1,%rax
shl    $0x9,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
add    $0x200,%rsi
mov    -0x38(%rbp),%rax
sub    $0x200,%rax
mov    %eax,%edx
call   1090 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x190,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
shl    $0x9,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %eax,%r8d
mov    $0x1,%esi
mov    $0x7a00,%edx
xor    %ecx,%ecx
call   10d0 <fill_daps@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     13b2 <barebox_overlay_mbr+0x1f2>
jmp    1407 <barebox_overlay_mbr+0x247>
xor    %edi,%edi
call   1030 <__ASSERT_VOID_CAST@plt>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1050 <barebox_linear_image@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     13de <barebox_overlay_mbr+0x21e>
jmp    1407 <barebox_overlay_mbr+0x247>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1,%esi
call   10a0 <store_pers_env_info@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     1402 <barebox_overlay_mbr+0x242>
jmp    1407 <barebox_overlay_mbr+0x247>
jmp    1407 <barebox_overlay_mbr+0x247>
mov    -0x28(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10b0 <munmap@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10b0 <munmap@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<barebox_overlay_mbr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %esi,%r13d
mov    %edi,%ebx
lea    0x10(%rsp),%rsi
call   10e0 <fstat@plt>
cmp    $0xffffffff,%eax
je     1361 <barebox_overlay_mbr+0x1a1>
mov    0x10(%rsp),%r14
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    0x2dea(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14,%rsi
mov    %ebx,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    0x2da9(%rip),%r15
cmp    (%r15),%rax
je     136a <barebox_overlay_mbr+0x1aa>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <check_for_valid_mbr@plt>
test   %eax,%eax
je     124e <barebox_overlay_mbr+0x8e>
mov    %eax,%ebp
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1345 <barebox_overlay_mbr+0x185>
mov    %r12,(%rsp)
shl    $0x9,%r12
add    %r14,%r12
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
mov    0x2d8f(%rip),%rax
or     (%rax),%edx
mov    0x2d76(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r12,%rsi
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
cmp    (%r15),%rax
je     137d <barebox_overlay_mbr+0x1bd>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12,%rsi
call   1070 <check_for_space@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    133a <barebox_overlay_mbr+0x17a>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x1be,%edx
call   1090 <memcpy@plt>
mov    (%rsp),%rax
lea    0x1(%rax),%rbp
mov    %rbp,%r15
shl    $0x9,%r15
add    %r13,%r15
mov    %rbx,%rsi
add    $0x200,%rsi
lea    -0x200(%r14),%edx
mov    %r15,%rdi
call   1090 <memcpy@plt>
mov    %r13,%rdi
add    $0x190,%rdi
mov    %rdi,0x8(%rsp)
mov    $0x1,%esi
mov    $0x7a00,%edx
xor    %ecx,%ecx
mov    %ebp,%r8d
call   10d0 <fill_daps@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    133a <barebox_overlay_mbr+0x17a>
xor    %edi,%edi
call   1030 <__ASSERT_VOID_CAST@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    (%rsp),%rdx
call   1050 <barebox_linear_image@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    133a <barebox_overlay_mbr+0x17a>
mov    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    (%rsp),%rdx
call   10a0 <store_pers_env_info@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %r12,%rsi
call   10b0 <munmap@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <munmap@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc98(%rip),%rdi
jmp    1371 <barebox_overlay_mbr+0x1b1>
lea    0xc95(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1350 <barebox_overlay_mbr+0x190>
lea    0xc82(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1345 <barebox_overlay_mbr+0x185>

LLVM IR (-O0):
%struct.stat = type { i64 }
%struct.DAPS = type { i32 }
@.str = [6 x i8] c"fstat\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.1 = [5 x i8] c"mmap\00"
@stderr = global i32 0
@.str.2 = [50 x i8] c"barebox image seems not valid: Bad MBR signature\0A\00"
@PROT_WRITE = global i32 0
define i32 @barebox_overlay_mbr(i32 %0, i32 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.stat
%12 = alloca %struct.DAPS*
%13 = alloca %struct.DAPS*
%14 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i64 %2, i64* %7
%15 = load i32, i32* %5
%16 = call i32 @fstat(i32 %15, %struct.stat* %11)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %129
20: ; preds = %3
%21 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%22 = load i64, i64* %21
%23 = load i32, i32* @PROT_READ
%24 = load i32, i32* @MAP_SHARED
%25 = load i32, i32* %5
%26 = call i8* @mmap(i32* null, i64 %22, i32 %23, i32 %24, i32 %25, i32 0)
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = load i8*, i8** @MAP_FAILED
%29 = icmp eq i8* %27, %28
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %129
32: ; preds = %20
%33 = load i8*, i8** %8
%34 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%35 = load i64, i64* %34
%36 = call i32 @check_for_valid_mbr(i8* %33, i64 %35)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %123
42: ; preds = %32
%43 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%44 = load i64, i64* %43
%45 = load i64, i64* %7
%46 = mul nsw i64 %45, 512
%47 = add nsw i64 %44, %46
store i64 %47, i64* %14
%48 = load i64, i64* %14
%49 = load i32, i32* @PROT_READ
%50 = load i32, i32* @PROT_WRITE
%51 = or i32 %49, %50
%52 = load i32, i32* @MAP_SHARED
%53 = load i32, i32* %6
%54 = call i8* @mmap(i32* null, i64 %48, i32 %51, i32 %52, i32 %53, i32 0)
store i8* %54, i8** %9
%55 = load i8*, i8** %9
%56 = load i8*, i8** @MAP_FAILED
%57 = icmp eq i8* %55, %56
br i1 %57, label %58, label %60
58: ; preds = %42
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %10
br label %123
60: ; preds = %42
%61 = load i8*, i8** %9
%62 = load i64, i64* %14
%63 = call i32 @check_for_space(i8* %61, i64 %62)
store i32 %63, i32* %10
%64 = load i32, i32* %10
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %60
br label %119
67: ; preds = %60
%68 = load i8*, i8** %9
%69 = load i8*, i8** %8
%70 = call i32 @memcpy(i8* %68, i8* %69, i32 446)
%71 = load i8*, i8** %9
%72 = load i64, i64* %7
%73 = add nsw i64 %72, 1
%74 = mul nsw i64 %73, 512
%75 = getelementptr i8, i8* %71, i64 %74
%76 = load i8*, i8** %8
%77 = getelementptr i8, i8* %76, i64 512
%78 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%79 = load i64, i64* %78
%80 = sub nsw i64 %79, 512
%81 = trunc i64 %80 to i32
%82 = call i32 @memcpy(i8* %75, i8* %77, i32 %81)
%83 = load i8*, i8** %9
%84 = getelementptr i8, i8* %83, i64 400
%85 = bitcast i8* %84 to %struct.DAPS*
store %struct.DAPS* %85, %struct.DAPS** %12
%86 = load i8*, i8** %9
%87 = load i64, i64* %7
%88 = add nsw i64 %87, 1
%89 = mul nsw i64 %88, 512
%90 = getelementptr i8, i8* %86, i64 %89
%91 = bitcast i8* %90 to %struct.DAPS*
store %struct.DAPS* %91, %struct.DAPS** %13
%92 = load %struct.DAPS*, %struct.DAPS** %12
%93 = load i64, i64* %7
%94 = add nsw i64 1, %93
%95 = trunc i64 %94 to i32
%96 = call i32 @fill_daps(%struct.DAPS* %92, i32 1, i32 31232, i32 0, i32 %95)
store i32 %96, i32* %10
%97 = load i32, i32* %10
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %100
99: ; preds = %67
br label %119
100: ; preds = %67
%101 = call i32 @__ASSERT_VOID_CAST(i32 0)
%102 = load %struct.DAPS*, %struct.DAPS** %13
%103 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%104 = load i64, i64* %103
%105 = trunc i64 %104 to i32
%106 = load i64, i64* %7
%107 = call i32 @barebox_linear_image(%struct.DAPS* %102, i32 %105, i64 %106)
store i32 %107, i32* %10
%108 = load i32, i32* %10
%109 = icmp ne i32 %108, 0
br i1 %109, label %110, label %111
110: ; preds = %100
br label %119
111: ; preds = %100
%112 = load %struct.DAPS*, %struct.DAPS** %12
%113 = load i64, i64* %7
%114 = call i32 @store_pers_env_info(%struct.DAPS* %112, i32 1, i64 %113)
store i32 %114, i32* %10
%115 = load i32, i32* %10
%116 = icmp ne i32 %115, 0
br i1 %116, label %117, label %118
117: ; preds = %111
br label %119
118: ; preds = %111
br label %119
119: ; preds = %118, %117, %110, %99, %66
%120 = load i8*, i8** %9
%121 = load i64, i64* %14
%122 = call i32 @munmap(i8* %120, i64 %121)
br label %123
123: ; preds = %119, %58, %39
%124 = load i8*, i8** %8
%125 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%126 = load i64, i64* %125
%127 = call i32 @munmap(i8* %124, i64 %126)
%128 = load i32, i32* %10
store i32 %128, i32* %4
br label %129
129: ; preds = %123, %30, %18
%130 = load i32, i32* %4
ret i32 %130
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.DAPS = type { i32 }
@.str = [6 x i8] c"fstat\00"
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.1 = [5 x i8] c"mmap\00"
@stderr = global i32 0
@.str.2 = [50 x i8] c"barebox image seems not valid: Bad MBR signature\0A\00"
@PROT_WRITE = global i32 0
define i32 @barebox_overlay_mbr(i32 %0, i32 %1, i64 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i32 @fstat(i32 %0, %struct.stat* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %68
10: ; preds = %3
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%12 = load i64, i64* %11
%13 = load i32, i32* @PROT_READ
%14 = load i32, i32* @MAP_SHARED
%15 = tail call i8* @mmap(i32* null, i64 %12, i32 %13, i32 %14, i32 %0, i32 0)
%16 = load i8*, i8** @MAP_FAILED
%17 = icmp eq i8* %15, %16
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %68
20: ; preds = %10
%21 = tail call i32 @check_for_valid_mbr(i8* %15, i64 %12)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %65
26: ; preds = %20
%27 = shl nsw i64 %2, 9
%28 = add nsw i64 %12, %27
%29 = load i32, i32* @PROT_READ
%30 = load i32, i32* @PROT_WRITE
%31 = or i32 %30, %29
%32 = load i32, i32* @MAP_SHARED
%33 = tail call i8* @mmap(i32* null, i64 %28, i32 %31, i32 %32, i32 %1, i32 0)
%34 = load i8*, i8** @MAP_FAILED
%35 = icmp eq i8* %33, %34
br i1 %35, label %36, label %38
36: ; preds = %26
%37 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %65
38: ; preds = %26
%39 = tail call i32 @check_for_space(i8* %33, i64 %28)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %62
41: ; preds = %38
%42 = tail call i32 @memcpy(i8* %33, i8* %15, i32 446)
%43 = add nsw i64 %2, 1
%44 = shl nsw i64 %43, 9
%45 = getelementptr i8, i8* %33, i64 %44
%46 = getelementptr i8, i8* %15, i64 512
%47 = trunc i64 %12 to i32
%48 = add i32 %47, -512
%49 = tail call i32 @memcpy(i8* %45, i8* %46, i32 %48)
%50 = getelementptr i8, i8* %33, i64 400
%51 = bitcast i8* %50 to %struct.DAPS*
%52 = trunc i64 %43 to i32
%53 = tail call i32 @fill_daps(%struct.DAPS* %51, i32 1, i32 31232, i32 0, i32 %52)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %62
55: ; preds = %41
%56 = bitcast i8* %45 to %struct.DAPS*
%57 = tail call i32 @__ASSERT_VOID_CAST(i32 0)
%58 = tail call i32 @barebox_linear_image(%struct.DAPS* %56, i32 %47, i64 %2)
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = tail call i32 @store_pers_env_info(%struct.DAPS* %51, i32 1, i64 %2)
br label %62
62: ; preds = %60, %55, %41, %38
%63 = phi i32 [ %39, %38 ], [ %53, %41 ], [ %58, %55 ], [ %61, %60 ]
%64 = tail call i32 @munmap(i8* %33, i64 %28)
br label %65
65: ; preds = %62, %36, %23
%66 = phi i32 [ %21, %23 ], [ -1, %36 ], [ %63, %62 ]
%67 = tail call i32 @munmap(i8* %15, i64 %12)
br label %68
68: ; preds = %65, %18, %8
%69 = phi i32 [ -1, %8 ], [ -1, %18 ], [ %66, %65 ]
ret i32 %69
}