#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*/ SEEK_END;
scalar_t__ calloc(size_t, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void add_sign(char *src_file, char *dst_file, int symbol) {
  FILE *fp_src_uboot = NULL;
  FILE *fp_dst_uboot = NULL;
  unsigned char *ptmp1 = NULL;
  unsigned char *addr = NULL;
  char *fn_src_uboot = src_file;
  char *fn_dst_uboot = dst_file;
  unsigned char *src = NULL;
  int fs = 0;
  int i = 0;
  fp_src_uboot = fopen(fn_src_uboot, "rb");
  if (NULL == fp_src_uboot) {
    printf("can't open uboot file for read(%s)\n", fn_src_uboot);
    return;
  }
  fp_dst_uboot = fopen(fn_dst_uboot, "wb");
  if (NULL == fp_src_uboot) {
    printf("can't open uboot file for read(%s)\n", fn_src_uboot);
    return;
  }
  fseek(fp_src_uboot, 0L, SEEK_END);
  fs = ftell(fp_src_uboot);
  printf("u-boot.bin file size= %dB\n", fs);
  rewind(fp_src_uboot);
  src = (unsigned char *)calloc((size_t)fs, 1);
  fread(src, 1, (size_t)fs, fp_src_uboot);
  ptmp1 = src;
  ptmp1 += 8;
  {
    *(ptmp1 + 0) = 0x00;
    *(ptmp1 + 1) = 0x20;
    *(ptmp1 + 2) = 0x41;
    *(ptmp1 + 3) = 0xE4;
  }
  fwrite(src, 1, (size_t)fs, fp_dst_uboot);
  free(src);
  fclose(fp_src_uboot);
  fclose(fp_dst_uboot);
}


x86 assembly (clang, -O0):
<add_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1230 <add_sign+0x90>
mov    -0x40(%rbp),%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    132f <add_sign+0x18f>
mov    -0x48(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    1267 <add_sign+0xc7>
mov    -0x40(%rbp),%rsi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    132f <add_sign+0x18f>
mov    -0x20(%rbp),%rdi
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <ftell@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%esi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <rewind@plt>
movslq -0x54(%rbp),%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
movslq -0x54(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movb   $0x20,0x1(%rax)
mov    -0x30(%rbp),%rax
movb   $0x41,0x2(%rax)
mov    -0x30(%rbp),%rax
movb   $0xe4,0x3(%rax)
mov    -0x50(%rbp),%rdi
movslq -0x54(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_sign>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe4b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1270 <add_sign+0xd0>
mov    %rax,%r15
lea    0xe5a(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
call   1090 <ftell@plt>
mov    %eax,%ebx
lea    0xe2e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1070 <rewind@plt>
movslq %ebx,%r12
mov    %r12,%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r15,%rcx
call   1040 <fread@plt>
movl   $0xe4412000,0x8(%rbx)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r14,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>
lea    0xd8c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [36 x i8] c"can't open uboot file for read(%s)\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@.str.3 = [27 x i8] c"u-boot.bin file size= %dB\0A\00"
define void @add_sign(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32* null, i32** %7
store i32* null, i32** %8
store i8* null, i8** %9
store i8* null, i8** %10
%16 = load i8*, i8** %4
store i8* %16, i8** %11
%17 = load i8*, i8** %5
store i8* %17, i8** %12
store i8* null, i8** %13
store i32 0, i32* %14
store i32 0, i32* %15
%18 = load i8*, i8** %11
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %7
%20 = load i32*, i32** %7
%21 = icmp eq i32* null, %20
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = load i8*, i8** %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %74
25: ; preds = %3
%26 = load i8*, i8** %12
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %8
%28 = load i32*, i32** %7
%29 = icmp eq i32* null, %28
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i8*, i8** %11
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %74
33: ; preds = %25
%34 = load i32*, i32** %7
%35 = load i32, i32* @SEEK_END
%36 = call i32 @fseek(i32* %34, i64 0, i32 %35)
%37 = load i32*, i32** %7
%38 = call i32 @ftell(i32* %37)
store i32 %38, i32* %14
%39 = load i32, i32* %14
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i32*, i32** %7
%42 = call i32 @rewind(i32* %41)
%43 = load i32, i32* %14
%44 = sext i32 %43 to i64
%45 = call i64 @calloc(i64 %44, i32 1)
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %13
%47 = load i8*, i8** %13
%48 = load i32, i32* %14
%49 = sext i32 %48 to i64
%50 = load i32*, i32** %7
%51 = call i32 @fread(i8* %47, i32 1, i64 %49, i32* %50)
%52 = load i8*, i8** %13
store i8* %52, i8** %9
%53 = load i8*, i8** %9
%54 = getelementptr inbounds i8, i8* %53, i64 8
store i8* %54, i8** %9
%55 = load i8*, i8** %9
%56 = getelementptr inbounds i8, i8* %55, i64 0
store i8 0, i8* %56
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8 32, i8* %58
%59 = load i8*, i8** %9
%60 = getelementptr inbounds i8, i8* %59, i64 2
store i8 65, i8* %60
%61 = load i8*, i8** %9
%62 = getelementptr inbounds i8, i8* %61, i64 3
store i8 -28, i8* %62
%63 = load i8*, i8** %13
%64 = load i32, i32* %14
%65 = sext i32 %64 to i64
%66 = load i32*, i32** %8
%67 = call i32 @fwrite(i8* %63, i32 1, i64 %65, i32* %66)
%68 = load i8*, i8** %13
%69 = call i32 @free(i8* %68)
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
%72 = load i32*, i32** %8
%73 = call i32 @fclose(i32* %72)
br label %74
74: ; preds = %33, %30, %22
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [36 x i8] c"can't open uboot file for read(%s)\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@.str.3 = [27 x i8] c"u-boot.bin file size= %dB\0A\00"
define void @add_sign(i8* %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %27
8: ; preds = %3
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %4, i64 0, i32 %10)
%12 = tail call i32 @ftell(i32* %4)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = tail call i32 @rewind(i32* %4)
%15 = sext i32 %12 to i64
%16 = tail call i64 @calloc(i64 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
%18 = tail call i32 @fread(i8* %17, i32 1, i64 %15, i32* %4)
%19 = getelementptr inbounds i8, i8* %17, i64 8
store i8 0, i8* %19
%20 = getelementptr inbounds i8, i8* %17, i64 9
store i8 32, i8* %20
%21 = getelementptr inbounds i8, i8* %17, i64 10
store i8 65, i8* %21
%22 = getelementptr inbounds i8, i8* %17, i64 11
store i8 -28, i8* %22
%23 = tail call i32 @fwrite(i8* %17, i32 1, i64 %15, i32* %9)
%24 = tail call i32 @free(i8* %17)
%25 = tail call i32 @fclose(i32* %4)
%26 = tail call i32 @fclose(i32* %9)
br label %27
27: ; preds = %8, %6
ret void
}