#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*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  int dummy;
};
struct stat {
  unsigned long st_size;
};
typedef int /*<<< orphan*/ boardMagic;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(unsigned char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ mkstemp(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
scalar_t__ stat(char *, struct stat *);
int strtol(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  FILE *fp1;
  FILE *fp2;
  char tmpFilename[50] = "packbin.XXXXXX";
  unsigned long imgSize, dateofday, timeofday;
  struct stat fileStat;
  unsigned long i;
  unsigned char ch;
  long boardMagic;
  struct timeval timeval;
  struct tm *ut;
  time_t tt;
  tt = time(0);
  gettimeofday(&timeval, 0);
  ut = localtime(&tt);
  printf("date %04d/%02d/%02d %02d:%02d:%02d \n", 1900 + ut->tm_year,
         ut->tm_mon + 1, ut->tm_mday, ut->tm_hour, ut->tm_min, ut->tm_sec);
  dateofday =
      ((ut->tm_year + 1900) << 16) + ((ut->tm_mon + 1) << 8) + (ut->tm_mday);
  timeofday =
      ((ut->tm_hour) << 24) + ((ut->tm_min) << 16) + ((ut->tm_sec) << 8);
  printf("%08lx %08lx\n", dateofday, timeofday);
  if (argc < 4) {
    printf("Usage: PACKHDR board_magic input_file output_file\n");
    printf("    board_magic   Hardware board's magic id.\n");
    printf("    input_file    Name of the input binary image file.\n");
    printf("    output_file   Name of the output binary image file.\n");
    return 0;
  }
  boardMagic = (((strtol(argv[1], 0, 0)) >> 24) |
                (((strtol(argv[1], 0, 0)) >> 8) & 0xFF00) |
                (((strtol(argv[1], 0, 0)) << 8) & 0xFF0000) |
                (((strtol(argv[1], 0, 0)) << 24) & 0xFF000000));
  if (boardMagic == 0x7fffffff || boardMagic == 0xffffff7f)
    boardMagic = 0xffffffff;
  printf("boardMagic=%x\n", boardMagic);
  if ((fp1 = fopen(argv[2], "r+b")) == 0) {
    printf("Cannot open %s !!\n", argv[1]);
    return -1;
  }
  if (stat(argv[2], &fileStat) != 0) {
    printf("Cannot get file statistics !!\n");
    fclose(fp1);
    exit(-1);
  }
  imgSize = fileStat.st_size;
  printf("Image Original Size = 0x%lx\n", imgSize);
  mkstemp(tmpFilename);
  if ((fp2 = fopen(tmpFilename, "w+b")) == 0) {
    printf("Cannot open temprary file !!\n");
    return -2;
  }
  fseek(fp1, 0L, SEEK_SET);
  fseek(fp2, 0L, SEEK_SET);
  fwrite((void *)&boardMagic, sizeof(boardMagic), 1, fp2);
  for (i = 0; i < imgSize; i++) {
    ch = fgetc(fp1);
    fputc(ch, fp2);
  }
  fclose(fp1);
  fclose(fp2);
  printf("Binary image %s generated!\n", argv[3]);
  remove(argv[3]);
  rename(tmpFilename, argv[3]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xdcc(%rip),%rsi
mov    $0x32,%edx
call   10c0 <memcpy@plt>
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,-0xac(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
lea    -0xac(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rax
mov    (%rax),%esi
add    $0x76c,%esi
mov    -0xa8(%rbp),%rax
mov    0x4(%rax),%edx
add    $0x1,%edx
mov    -0xa8(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0xa8(%rbp),%rax
mov    0xc(%rax),%r8d
mov    -0xa8(%rbp),%rax
mov    0x10(%rax),%r9d
mov    -0xa8(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xd79(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xa8(%rbp),%rax
mov    (%rax),%eax
add    $0x76c,%eax
shl    $0x10,%eax
mov    -0xa8(%rbp),%rcx
mov    0x4(%rcx),%ecx
add    $0x1,%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0xa8(%rbp),%rcx
add    0x8(%rcx),%eax
cltq
mov    %rax,-0x70(%rbp)
mov    -0xa8(%rbp),%rax
mov    0xc(%rax),%eax
shl    $0x18,%eax
mov    -0xa8(%rbp),%rcx
mov    0x10(%rcx),%ecx
shl    $0x10,%ecx
add    %ecx,%eax
mov    -0xa8(%rbp),%rcx
mov    0x14(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rsi
mov    -0x78(%rbp),%rdx
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x4,-0x8(%rbp)
jge    138b <main+0x17b>
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    162c <main+0x41c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10b0 <strtol@plt>
sar    $0x18,%eax
mov    %eax,-0xb8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10b0 <strtol@plt>
mov    %eax,%ecx
mov    -0xb8(%rbp),%eax
sar    $0x8,%ecx
and    $0xff00,%ecx
or     %ecx,%eax
mov    %eax,-0xb4(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10b0 <strtol@plt>
mov    %eax,%ecx
mov    -0xb4(%rbp),%eax
shl    $0x8,%ecx
and    $0xff0000,%ecx
or     %ecx,%eax
mov    %eax,-0xb0(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10b0 <strtol@plt>
mov    %eax,%ecx
mov    -0xb0(%rbp),%eax
shl    $0x18,%ecx
and    $0xff000000,%ecx
or     %ecx,%eax
mov    %eax,%eax
mov    %rax,-0x98(%rbp)
cmpq   $0x7fffffff,-0x98(%rbp)
ff ff ff 7f
je     1449 <main+0x239>
mov    $0xffffff7f,%eax
cmp    %rax,-0x98(%rbp)
jne    1455 <main+0x245>
mov    $0xffffffff,%eax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rsi
lea    0xcd3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xccc(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    14ae <main+0x29e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    162c <main+0x41c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x80(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
je     14ea <main+0x2da>
lea    0xc8c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>
mov    -0x80(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rsi
lea    0xc7e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x60(%rbp),%rdi
call   10e0 <mkstemp@plt>
lea    -0x60(%rbp),%rdi
lea    0xc80(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1545 <main+0x335>
lea    0xc6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    162c <main+0x41c>
mov    -0x18(%rbp),%rdi
mov    0x2a90(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10f0 <fseek@plt>
mov    -0x20(%rbp),%rdi
mov    0x2a7a(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10f0 <fseek@plt>
lea    -0x98(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x8,%esi
mov    $0x1,%edx
call   1130 <fwrite@plt>
movq   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%rax
cmp    -0x68(%rbp),%rax
jae    15df <main+0x3cf>
mov    -0x18(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %al,-0x89(%rbp)
mov    -0x89(%rbp),%al
mov    -0x20(%rbp),%rsi
movzbl %al,%edi
call   1090 <fputc@plt>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    1596 <main+0x386>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xbba(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <remove@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1110 <rename@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
movaps 0xdf6(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xdda(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xdbe(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movw   $0x0,0x60(%rsp)
xor    %r14d,%r14d
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,0x14(%rsp)
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
lea    0x14(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
mov    $0x76c,%esi
add    (%rax),%esi
mov    0x4(%rax),%edx
mov    0x8(%rax),%ecx
add    $0x1,%edx
mov    0xc(%rax),%r8d
mov    0x10(%rax),%r9d
mov    0x14(%rax),%eax
mov    %eax,(%rsp)
lea    0xd98(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%rbx),%eax
mov    0x4(%rbx),%ecx
shl    $0x10,%eax
shl    $0x8,%ecx
add    %eax,%ecx
mov    0x8(%rbx),%eax
add    %ecx,%eax
add    $0x76c0100,%eax
movslq %eax,%rsi
mov    0xc(%rbx),%eax
shl    $0x18,%eax
mov    0x10(%rbx),%ecx
shl    $0x10,%ecx
add    %eax,%ecx
mov    0x14(%rbx),%eax
shl    $0x8,%eax
add    %ecx,%eax
movslq %eax,%rdx
lea    0xd7c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x3,%ebp
jg     131c <main+0x10c>
lea    0xe14(%rip),%rdi
call   1050 <puts@plt>
lea    0xe3a(%rip),%rdi
call   1050 <puts@plt>
lea    0xe5b(%rip),%rdi
call   1050 <puts@plt>
lea    0xe86(%rip),%rdi
call   1050 <puts@plt>
jmp    14e0 <main+0x2d0>
mov    0x8(%r15),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <strtol@plt>
mov    %eax,%ebp
sar    $0x18,%ebp
mov    0x8(%r15),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <strtol@plt>
mov    %eax,%ebx
shr    $0x8,%ebx
and    $0xff00,%ebx
or     %ebp,%ebx
mov    0x8(%r15),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <strtol@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
and    $0xff0000,%ebp
mov    0x8(%r15),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <strtol@plt>
shl    $0x18,%eax
or     %ebp,%eax
or     %ebx,%eax
cmp    $0xffffff7f,%eax
mov    $0xffffffff,%ecx
mov    %rax,%rsi
cmove  %rcx,%rsi
cmp    $0x7fffffff,%eax
cmove  %rcx,%rsi
mov    %rsi,0x20(%rsp)
lea    0xcca(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%r15),%rdi
lea    0xcc7(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     14b4 <main+0x2a4>
mov    %rax,%r12
mov    0x10(%r15),%rdi
lea    0x28(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
jne    14f2 <main+0x2e2>
mov    0x28(%rsp),%rbx
lea    0xcaa(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
call   10e0 <mkstemp@plt>
lea    0xca9(%rip),%rsi
mov    %rbp,%rdi
call   1100 <fopen@plt>
test   %rax,%rax
je     14ce <main+0x2be>
mov    %rax,%r13
mov    0x2bc7(%rip),%rbp
mov    0x0(%rbp),%edx
xor    %r14d,%r14d
mov    %r12,%rdi
xor    %esi,%esi
call   10f0 <fseek@plt>
mov    0x0(%rbp),%edx
mov    %r13,%rdi
xor    %esi,%esi
call   10f0 <fseek@plt>
lea    0x20(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1130 <fwrite@plt>
test   %rbx,%rbx
je     1479 <main+0x269>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1090 <fgetc@plt>
movzbl %al,%edi
mov    %r13,%rsi
call   10a0 <fputc@plt>
add    $0xffffffffffffffff,%rbx
jne    1460 <main+0x250>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    0x18(%r15),%rsi
lea    0xc17(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x18(%r15),%rdi
call   1040 <remove@plt>
mov    0x18(%r15),%rsi
lea    0x30(%rsp),%rdi
call   1110 <rename@plt>
jmp    14e0 <main+0x2d0>
mov    0x8(%r15),%rsi
lea    0xbb8(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%r14d
jmp    14e0 <main+0x2d0>
lea    0xbf2(%rip),%rdi
call   1050 <puts@plt>
mov    $0xfffffffe,%r14d
mov    %r14d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbeb(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@__const.main.tmpFilename = [50 x i8] c"packbin.XXXXXX\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [37 x i8] c"date %04d/%02d/%02d %02d:%02d:%02d \0A\00"
@.str.1 = [13 x i8] c"%08lx %08lx\0A\00"
@.str.2 = [51 x i8] c"Usage: PACKHDR board_magic input_file output_file\0A\00"
@.str.3 = [46 x i8] c" board_magic Hardware board's magic id.\0A\00"
@.str.4 = [56 x i8] c" input_file Name of the input binary image file.\0A\00"
@.str.5 = [57 x i8] c" output_file Name of the output binary image file.\0A\00"
@.str.6 = [15 x i8] c"boardMagic=%x\0A\00"
@.str.7 = [4 x i8] c"r+b\00"
@.str.8 = [19 x i8] c"Cannot open %s !!\0A\00"
@.str.9 = [31 x i8] c"Cannot get file statistics !!\0A\00"
@.str.10 = [29 x i8] c"Image Original Size = 0x%lx\0A\00"
@.str.11 = [4 x i8] c"w+b\00"
@.str.12 = [30 x i8] c"Cannot open temprary file !!\0A\00"
@SEEK_SET = global i32 0
@.str.13 = [28 x i8] c"Binary image %s generated!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [50 x i8]
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca %struct.stat
%13 = alloca i64
%14 = alloca i8
%15 = alloca i64
%16 = alloca %struct.timeval
%17 = alloca %struct.tm*
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = bitcast [50 x i8]* %8 to i8*
%20 = call i32 @time(i32 0)
store i32 %20, i32* %18
%21 = call i32 @gettimeofday(%struct.timeval* %16, i32 0)
%22 = call %struct.tm* @localtime(i32* %18)
store %struct.tm* %22, %struct.tm** %17
%23 = load %struct.tm*, %struct.tm** %17
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = add nsw i32 1900, %25
%27 = load %struct.tm*, %struct.tm** %17
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = add nsw i32 %29, 1
%31 = load %struct.tm*, %struct.tm** %17
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 2
%33 = load i32, i32* %32
%34 = load %struct.tm*, %struct.tm** %17
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 3
%36 = load i32, i32* %35
%37 = load %struct.tm*, %struct.tm** %17
%38 = getelementptr inbounds %struct.tm, %struct.tm* %37, i32 0, i32 4
%39 = load i32, i32* %38
%40 = load %struct.tm*, %struct.tm** %17
%41 = getelementptr inbounds %struct.tm, %struct.tm* %40, i32 0, i32 5
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %30, i32 %33, i32 %36, i32 %39, i32 %42)
%44 = load %struct.tm*, %struct.tm** %17
%45 = getelementptr inbounds %struct.tm, %struct.tm* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = add nsw i32 %46, 1900
%48 = shl i32 %47, 16
%49 = load %struct.tm*, %struct.tm** %17
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 1
%51 = load i32, i32* %50
%52 = add nsw i32 %51, 1
%53 = shl i32 %52, 8
%54 = add nsw i32 %48, %53
%55 = load %struct.tm*, %struct.tm** %17
%56 = getelementptr inbounds %struct.tm, %struct.tm* %55, i32 0, i32 2
%57 = load i32, i32* %56
%58 = add nsw i32 %54, %57
%59 = sext i32 %58 to i64
store i64 %59, i64* %10
%60 = load %struct.tm*, %struct.tm** %17
%61 = getelementptr inbounds %struct.tm, %struct.tm* %60, i32 0, i32 3
%62 = load i32, i32* %61
%63 = shl i32 %62, 24
%64 = load %struct.tm*, %struct.tm** %17
%65 = getelementptr inbounds %struct.tm, %struct.tm* %64, i32 0, i32 4
%66 = load i32, i32* %65
%67 = shl i32 %66, 16
%68 = add nsw i32 %63, %67
%69 = load %struct.tm*, %struct.tm** %17
%70 = getelementptr inbounds %struct.tm, %struct.tm* %69, i32 0, i32 5
%71 = load i32, i32* %70
%72 = shl i32 %71, 8
%73 = add nsw i32 %68, %72
%74 = sext i32 %73 to i64
store i64 %74, i64* %11
%75 = load i64, i64* %10
%76 = load i64, i64* %11
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %75, i64 %76)
%78 = load i32, i32* %4
%79 = icmp slt i32 %78, 4
br i1 %79, label %80, label %85
80: ; preds = %2
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0))
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %196
85: ; preds = %2
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 1
%88 = load i8*, i8** %87
%89 = call i32 @strtol(i8* %88, i32 0, i32 0)
%90 = ashr i32 %89, 24
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 1
%93 = load i8*, i8** %92
%94 = call i32 @strtol(i8* %93, i32 0, i32 0)
%95 = ashr i32 %94, 8
%96 = and i32 %95, 65280
%97 = or i32 %90, %96
%98 = load i8**, i8*** %5
%99 = getelementptr inbounds i8*, i8** %98, i64 1
%100 = load i8*, i8** %99
%101 = call i32 @strtol(i8* %100, i32 0, i32 0)
%102 = shl i32 %101, 8
%103 = and i32 %102, 16711680
%104 = or i32 %97, %103
%105 = load i8**, i8*** %5
%106 = getelementptr inbounds i8*, i8** %105, i64 1
%107 = load i8*, i8** %106
%108 = call i32 @strtol(i8* %107, i32 0, i32 0)
%109 = shl i32 %108, 24
%110 = and i32 %109, -16777216
%111 = or i32 %104, %110
%112 = zext i32 %111 to i64
store i64 %112, i64* %15
%113 = load i64, i64* %15
%114 = icmp eq i64 %113, 2147483647
br i1 %114, label %118, label %115
115: ; preds = %85
%116 = load i64, i64* %15
%117 = icmp eq i64 %116, 4294967167
br i1 %117, label %118, label %119
118: ; preds = %115, %85
store i64 4294967295, i64* %15
br label %119
119: ; preds = %118, %115
%120 = load i64, i64* %15
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i64 %120)
%122 = load i8**, i8*** %5
%123 = getelementptr inbounds i8*, i8** %122, i64 2
%124 = load i8*, i8** %123
%125 = call i32* @fopen(i8* %124, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
store i32* %125, i32** %6
%126 = icmp eq i32* %125, null
br i1 %126, label %127, label %132
127: ; preds = %119
%128 = load i8**, i8*** %5
%129 = getelementptr inbounds i8*, i8** %128, i64 1
%130 = load i8*, i8** %129
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %130)
store i32 -1, i32* %3
br label %196
132: ; preds = %119
%133 = load i8**, i8*** %5
%134 = getelementptr inbounds i8*, i8** %133, i64 2
%135 = load i8*, i8** %134
%136 = call i64 @stat(i8* %135, %struct.stat* %12)
%137 = icmp ne i64 %136, 0
br i1 %137, label %138, label %143
138: ; preds = %132
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0))
%140 = load i32*, i32** %6
%141 = call i32 @fclose(i32* %140)
%142 = call i32 @exit(i32 -1)
unreachable
143: ; preds = %132
%144 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%145 = load i64, i64* %144
store i64 %145, i64* %9
%146 = load i64, i64* %9
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i64 %146)
%148 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%149 = call i32 @mkstemp(i8* %148)
%150 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%151 = call i32* @fopen(i8* %150, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
store i32* %151, i32** %7
%152 = icmp eq i32* %151, null
br i1 %152, label %153, label %155
153: ; preds = %143
%154 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0))
store i32 -2, i32* %3
br label %196
155: ; preds = %143
%156 = load i32*, i32** %6
%157 = load i32, i32* @SEEK_SET
%158 = call i32 @fseek(i32* %156, i64 0, i32 %157)
%159 = load i32*, i32** %7
%160 = load i32, i32* @SEEK_SET
%161 = call i32 @fseek(i32* %159, i64 0, i32 %160)
%162 = bitcast i64* %15 to i8*
%163 = load i32*, i32** %7
%164 = call i32 @fwrite(i8* %162, i32 8, i32 1, i32* %163)
store i64 0, i64* %13
br label %165
165: ; preds = %175, %155
%166 = load i64, i64* %13
%167 = load i64, i64* %9
%168 = icmp ult i64 %166, %167
br i1 %168, label %169, label %178
169: ; preds = %165
%170 = load i32*, i32** %6
%171 = call zeroext i8 @fgetc(i32* %170)
store i8 %171, i8* %14
%172 = load i8, i8* %14
%173 = load i32*, i32** %7
%174 = call i32 @fputc(i8 zeroext %172, i32* %173)
br label %175
175: ; preds = %169
%176 = load i64, i64* %13
%177 = add i64 %176, 1
store i64 %177, i64* %13
br label %165
178: ; preds = %165
%179 = load i32*, i32** %6
%180 = call i32 @fclose(i32* %179)
%181 = load i32*, i32** %7
%182 = call i32 @fclose(i32* %181)
%183 = load i8**, i8*** %5
%184 = getelementptr inbounds i8*, i8** %183, i64 3
%185 = load i8*, i8** %184
%186 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0), i8* %185)
%187 = load i8**, i8*** %5
%188 = getelementptr inbounds i8*, i8** %187, i64 3
%189 = load i8*, i8** %188
%190 = call i32 @remove(i8* %189)
%191 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%192 = load i8**, i8*** %5
%193 = getelementptr inbounds i8*, i8** %192, i64 3
%194 = load i8*, i8** %193
%195 = call i32 @rename(i8* %191, i8* %194)
store i32 0, i32* %3
br label %196
196: ; preds = %178, %153, %127, %80
%197 = load i32, i32* %3
ret i32 %197
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@__const.main.tmpFilename = [50 x i8] c"packbin.XXXXXX\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [37 x i8] c"date %04d/%02d/%02d %02d:%02d:%02d \0A\00"
@.str.1 = [13 x i8] c"%08lx %08lx\0A\00"
@.str.6 = [15 x i8] c"boardMagic=%x\0A\00"
@.str.7 = [4 x i8] c"r+b\00"
@.str.8 = [19 x i8] c"Cannot open %s !!\0A\00"
@.str.10 = [29 x i8] c"Image Original Size = 0x%lx\0A\00"
@.str.11 = [4 x i8] c"w+b\00"
@SEEK_SET = global i32 0
@.str.13 = [28 x i8] c"Binary image %s generated!\0A\00"
@str = [29 x i8] c"Cannot open temprary file !!\00"
@str.14 = [30 x i8] c"Cannot get file statistics !!\00"
@str.15 = [50 x i8] c"Usage: PACKHDR board_magic input_file output_file\00"
@str.16 = [45 x i8] c" board_magic Hardware board's magic id.\00"
@str.17 = [55 x i8] c" input_file Name of the input binary image file.\00"
@str.18 = [56 x i8] c" output_file Name of the output binary image file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = alloca %struct.stat
%5 = alloca i64
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%9 = bitcast %struct.stat* %4 to i8*
%10 = bitcast i64* %5 to i8*
%11 = bitcast %struct.timeval* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = tail call i32 @time(i32 0)
store i32 %13, i32* %7
%14 = call i32 @gettimeofday(%struct.timeval* %6, i32 0)
%15 = call %struct.tm* @localtime(i32* %7)
%16 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 0
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 1900
%19 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
%22 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 2
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 3
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 4
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %15, i64 0, i32 5
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %21, i32 %23, i32 %25, i32 %27, i32 %29)
%31 = load i32, i32* %16
%32 = shl i32 %31, 16
%33 = load i32, i32* %19
%34 = shl i32 %33, 8
%35 = load i32, i32* %22
%36 = add i32 %32, 124518656
%37 = add i32 %36, %34
%38 = add i32 %37, %35
%39 = sext i32 %38 to i64
%40 = load i32, i32* %24
%41 = shl i32 %40, 24
%42 = load i32, i32* %26
%43 = shl i32 %42, 16
%44 = add nsw i32 %43, %41
%45 = load i32, i32* %28
%46 = shl i32 %45, 8
%47 = add nsw i32 %44, %46
%48 = sext i32 %47 to i64
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %39, i64 %48)
%50 = icmp slt i32 %0, 4
br i1 %50, label %51, label %56
51: ; preds = %2
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.15, i64 0, i64 0))
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.16, i64 0, i64 0))
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.17, i64 0, i64 0))
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.18, i64 0, i64 0))
br label %128
56: ; preds = %2
%57 = getelementptr inbounds i8*, i8** %1, i64 1
%58 = load i8*, i8** %57
%59 = call i32 @strtol(i8* %58, i32 0, i32 0)
%60 = ashr i32 %59, 24
%61 = load i8*, i8** %57
%62 = call i32 @strtol(i8* %61, i32 0, i32 0)
%63 = lshr i32 %62, 8
%64 = and i32 %63, 65280
%65 = or i32 %64, %60
%66 = load i8*, i8** %57
%67 = call i32 @strtol(i8* %66, i32 0, i32 0)
%68 = shl i32 %67, 8
%69 = and i32 %68, 16711680
%70 = or i32 %65, %69
%71 = load i8*, i8** %57
%72 = call i32 @strtol(i8* %71, i32 0, i32 0)
%73 = shl i32 %72, 24
%74 = or i32 %70, %73
%75 = zext i32 %74 to i64
%76 = icmp eq i32 %74, 2147483647
%77 = icmp eq i32 %74, -129
%78 = or i1 %76, %77
%79 = select i1 %78, i64 4294967295, i64 %75
store i64 %79, i64* %5
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i64 %79)
%81 = getelementptr inbounds i8*, i8** %1, i64 2
%82 = load i8*, i8** %81
%83 = call i32* @fopen(i8* %82, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%84 = icmp eq i32* %83, null
br i1 %84, label %85, label %88
85: ; preds = %56
%86 = load i8*, i8** %57
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %86)
br label %128
88: ; preds = %56
%89 = load i8*, i8** %81
%90 = call i64 @stat(i8* %89, %struct.stat* %4)
%91 = icmp eq i64 %90, 0
br i1 %91, label %96, label %92
92: ; preds = %88
%93 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.14, i64 0, i64 0))
%94 = call i32 @fclose(i32* %83)
%95 = call i32 @exit(i32 -1)
unreachable
96: ; preds = %88
%97 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%98 = load i64, i64* %97
%99 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0), i64 %98)
%100 = call i32 @mkstemp(i8* %8)
%101 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%102 = icmp eq i32* %101, null
br i1 %102, label %103, label %105
103: ; preds = %96
%104 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %128
105: ; preds = %96
%106 = load i32, i32* @SEEK_SET
%107 = call i32 @fseek(i32* %83, i64 0, i32 %106)
%108 = load i32, i32* @SEEK_SET
%109 = call i32 @fseek(i32* %101, i64 0, i32 %108)
%110 = call i32 @fwrite(i8* %10, i32 8, i32 1, i32* %101)
%111 = icmp eq i64 %98, 0
br i1 %111, label %118, label %112
112: ; preds = %105, %112
%113 = phi i64 [ %116, %112 ], [ 0, %105 ]
%114 = call zeroext i8 @fgetc(i32* %83)
%115 = call i32 @fputc(i8 zeroext %114, i32* %101)
%116 = add nuw i64 %113, 1
%117 = icmp eq i64 %116, %98
br i1 %117, label %118, label %112
118: ; preds = %112, %105
%119 = call i32 @fclose(i32* %83)
%120 = call i32 @fclose(i32* %101)
%121 = getelementptr inbounds i8*, i8** %1, i64 3
%122 = load i8*, i8** %121
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0), i8* %122)
%124 = load i8*, i8** %121
%125 = call i32 @remove(i8* %124)
%126 = load i8*, i8** %121
%127 = call i32 @rename(i8* %8, i8* %126)
br label %128
128: ; preds = %118, %103, %85, %51
%129 = phi i32 [ 0, %51 ], [ -1, %85 ], [ -2, %103 ], [ 0, %118 ]
ret i32 %129
}