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

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ copy_cbyc(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, unsigned int,
                         int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, unsigned int,
                          int /*<<< orphan*/ *);
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ memset(unsigned char *, char, int);
int /*<<< orphan*/ ncmp_cbyc(unsigned char *, unsigned char *, unsigned int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ remove(char *);
int rename(char *, char *);
unsigned int to_intconvertor(unsigned char *);
void remove_old_cfg(int idcode, unsigned char frame[]) {
  FILE *file, *newfile;
  int result;
  unsigned int idCODE, framesize;
  unsigned char *s, id[3], *line, frame_len[2];
  unsigned long fileLen;
  file = fopen("cfg.bin", "rb");
  newfile = fopen("ncfg.bin", "wb");
  if (file != NULL) {
    fseek(file, 0, SEEK_END);
    fileLen = ftell(file);
    fseek(file, 0, SEEK_SET);
    printf("BEFORE REMOVAL OF OLDFRAME FILE LEN %ld\n", fileLen);
    while (fileLen != 0) {
      fseek(file, 2, SEEK_CUR);
      fread(frame_len, sizeof(unsigned char), 2, file);
      fseek(file, -4, SEEK_CUR);
      framesize = to_intconvertor(frame_len);
      line = malloc(framesize * sizeof(unsigned char));
      memset(line, '\0', sizeof(line));
      fread(line, sizeof(unsigned char), framesize, file);
      s = line;
      s += 4;
      copy_cbyc(id, s, 2);
      id[2] = '\0';
      idCODE = to_intconvertor(id);
      if (idCODE == idcode) {
        printf("IDcode of new cfg MATCHED with old cfg in file cfg.bin!\n");
        break;
      } else {
        fwrite(line, sizeof(unsigned char), framesize, newfile);
        free(line);
        fileLen -= framesize;
      }
    }
    unsigned int len;
    unsigned char *p = frame;
    p += 2;
    copy_cbyc(frame_len, p, 2);
    len = to_intconvertor(frame_len);
    fwrite(frame, sizeof(unsigned char), len, newfile);
    while (fileLen != 0) {
      fseek(file, 2, SEEK_CUR);
      fread(frame_len, sizeof(unsigned char), 2, file);
      fseek(file, -4, SEEK_CUR);
      framesize = to_intconvertor(frame_len);
      line = malloc(framesize * sizeof(unsigned char));
      memset(line, '\0', sizeof(line));
      fread(line, sizeof(unsigned char), framesize, file);
      if (!ncmp_cbyc(line, frame, framesize)) {
        break;
      } else {
        fwrite(frame, sizeof(unsigned char), framesize, newfile);
        free(line);
        fileLen -= framesize;
      }
    }
    fclose(file);
    fclose(newfile);
    if (remove("cfg.bin") != 0)
      perror("Error deleting file");
    result = rename("ncfg.bin", "cfg.bin");
    if (result == 0)
      printf("File successfully renamed\n");
    else
      perror("Error renaming file\n");
  } else {
    perror("cfg.bin");
  }
}


x86 assembly (clang, -O0):
<remove_old_cfg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdee(%rip),%rdi
lea    0xde3(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xdd6(%rip),%rdi
lea    0xdd8(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     154d <remove_old_cfg+0x34d>
mov    -0x18(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <ftell@plt>
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d5c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x58(%rbp),%rsi
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpq   $0x0,-0x58(%rbp)
je     13aa <remove_old_cfg+0x1aa>
mov    -0x18(%rbp),%rdi
mov    0x2d3b(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   10d0 <fseek@plt>
lea    -0x4a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <fread@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d0d(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   10d0 <fseek@plt>
lea    -0x4a(%rbp),%rdi
call   1110 <to_intconvertor@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
lea    -0x3b(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x2,%edx
call   1080 <copy_cbyc@plt>
movb   $0x0,-0x39(%rbp)
lea    -0x3b(%rbp),%rdi
call   1110 <to_intconvertor@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    1377 <remove_old_cfg+0x177>
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    13aa <remove_old_cfg+0x1aa>
mov    -0x48(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1120 <fwrite@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x58(%rbp)
jmp    128f <remove_old_cfg+0x8f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x68(%rbp)
lea    -0x4a(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    $0x2,%edx
call   1080 <copy_cbyc@plt>
lea    -0x4a(%rbp),%rdi
call   1110 <to_intconvertor@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x5c(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1120 <fwrite@plt>
cmpq   $0x0,-0x58(%rbp)
je     14d5 <remove_old_cfg+0x2d5>
mov    -0x18(%rbp),%rdi
mov    0x2bd9(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   10d0 <fseek@plt>
lea    -0x4a(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <fread@plt>
mov    -0x18(%rbp),%rdi
mov    0x2bab(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   10d0 <fseek@plt>
lea    -0x4a(%rbp),%rdi
call   1110 <to_intconvertor@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
shl    $0x0,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
mov    -0x48(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1090 <ncmp_cbyc@plt>
cmp    $0x0,%eax
jne    14a2 <remove_old_cfg+0x2a2>
jmp    14d5 <remove_old_cfg+0x2d5>
mov    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1120 <fwrite@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
mov    -0x58(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x58(%rbp)
jmp    13f1 <remove_old_cfg+0x1f1>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xb16(%rip),%rdi
call   1040 <remove@plt>
cmp    $0x0,%rax
je     1509 <remove_old_cfg+0x309>
lea    0xb6d(%rip),%rdi
call   10f0 <perror@plt>
lea    0xaf3(%rip),%rdi
lea    0xaed(%rip),%rsi
call   1100 <rename@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    153c <remove_old_cfg+0x33c>
lea    0xb55(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1548 <remove_old_cfg+0x348>
lea    0xb5d(%rip),%rdi
call   10f0 <perror@plt>
jmp    1559 <remove_old_cfg+0x359>
lea    0xab0(%rip),%rdi
call   10f0 <perror@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_old_cfg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r12
mov    %edi,0x1c(%rsp)
lea    0xdd8(%rip),%rdi
lea    0xdcd(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%r15
lea    0xdc1(%rip),%rdi
lea    0xdc3(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %r15,%r15
je     14e2 <remove_old_cfg+0x2d2>
mov    0x2d85(%rip),%rax
mov    (%rax),%edx
xor    %r13d,%r13d
mov    %r15,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %r15,%rdi
call   10c0 <ftell@plt>
mov    %rax,%r14
mov    0x2d4c(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
lea    0xd78(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
test   %r14,%r14
je     139e <remove_old_cfg+0x18e>
mov    %r12,0x20(%rsp)
mov    %r14,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2d19(%rip),%rbx
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0x2,%esi
call   10e0 <fseek@plt>
lea    0xb(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %r15,%rcx
call   1060 <fread@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0xfffffffc,%esi
call   10e0 <fseek@plt>
mov    %rbp,%rdi
call   1120 <to_intconvertor@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10b0 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r15,%rcx
call   1060 <fread@plt>
lea    0x4(%r14),%rsi
lea    0xd(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1090 <copy_cbyc@plt>
movb   $0x0,0xf(%rsp)
mov    %rbx,%rdi
call   1120 <to_intconvertor@plt>
cmp    0x1c(%rsp),%eax
je     138d <remove_old_cfg+0x17d>
mov    %r12d,%ebx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    0x10(%rsp),%rcx
call   1130 <fwrite@plt>
mov    %r14,%rdi
call   1030 <free@plt>
sub    %rbx,%r13
jne    12c0 <remove_old_cfg+0xb0>
xor    %r13d,%r13d
jmp    1399 <remove_old_cfg+0x189>
lea    0xce7(%rip),%rdi
call   1050 <puts@plt>
mov    0x20(%rsp),%r12
lea    0x2(%r12),%rsi
lea    0xb(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1090 <copy_cbyc@plt>
mov    %rbx,%rdi
call   1120 <to_intconvertor@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    0x10(%rsp),%rcx
call   1130 <fwrite@plt>
test   %r13,%r13
je     148d <remove_old_cfg+0x27d>
nopw   0x0(%rax,%rax,1)
mov    0x2bf9(%rip),%rbx
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0x2,%esi
call   10e0 <fseek@plt>
lea    0xb(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %r15,%rcx
call   1060 <fread@plt>
mov    (%rbx),%edx
mov    %r15,%rdi
mov    $0xfffffffc,%esi
call   10e0 <fseek@plt>
mov    %rbp,%rdi
call   1120 <to_intconvertor@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10b0 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r15,%rcx
call   1060 <fread@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   10a0 <ncmp_cbyc@plt>
test   %eax,%eax
je     148d <remove_old_cfg+0x27d>
mov    %ebp,%r14d
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    0x10(%rsp),%rcx
call   1130 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
sub    %r14,%r13
jne    13e0 <remove_old_cfg+0x1d0>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1070 <fclose@plt>
lea    0xb5e(%rip),%rdi
call   1040 <remove@plt>
test   %rax,%rax
jne    14fc <remove_old_cfg+0x2ec>
lea    0xb4c(%rip),%rdi
lea    0xb46(%rip),%rsi
call   1110 <rename@plt>
test   %eax,%eax
jne    150a <remove_old_cfg+0x2fa>
lea    0xb93(%rip),%rdi
call   1050 <puts@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb1b(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1100 <perror@plt>
lea    0xb35(%rip),%rdi
call   1100 <perror@plt>
jmp    14b0 <remove_old_cfg+0x2a0>
lea    0xb3b(%rip),%rdi
call   1100 <perror@plt>
jmp    14d3 <remove_old_cfg+0x2c3>

LLVM IR (-O0):
@.str = [8 x i8] c"cfg.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [9 x i8] c"ncfg.bin\00"
@.str.3 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [41 x i8] c"BEFORE REMOVAL OF OLDFRAME FILE LEN %ld\0A\00"
@SEEK_CUR = global i32 0
@.str.5 = [57 x i8] c"IDcode of new cfg MATCHED with old cfg in file cfg.bin!\0A\00"
@.str.6 = [20 x i8] c"Error deleting file\00"
@.str.7 = [27 x i8] c"File successfully renamed\0A\00"
@.str.8 = [21 x i8] c"Error renaming file\0A\00"
define void @remove_old_cfg(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [3 x i8]
%12 = alloca i8*
%13 = alloca [2 x i8]
%14 = alloca i64
%15 = alloca i32
%16 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%17 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %5
%18 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %5
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %159
21: ; preds = %2
%22 = load i32*, i32** %5
%23 = load i32, i32* @SEEK_END
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i32*, i32** %5
%26 = call i64 @ftell(i32* %25)
store i64 %26, i64* %14
%27 = load i32*, i32** %5
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %27, i32 0, i32 %28)
%30 = load i64, i64* %14
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i64 %30)
br label %32
32: ; preds = %83, %21
%33 = load i64, i64* %14
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %84
35: ; preds = %32
%36 = load i32*, i32** %5
%37 = load i32, i32* @SEEK_CUR
%38 = call i32 @fseek(i32* %36, i32 2, i32 %37)
%39 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%40 = load i32*, i32** %5
%41 = call i32 @fread(i8* %39, i32 1, i32 2, i32* %40)
%42 = load i32*, i32** %5
%43 = load i32, i32* @SEEK_CUR
%44 = call i32 @fseek(i32* %42, i32 -4, i32 %43)
%45 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%46 = call i32 @to_intconvertor(i8* %45)
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = zext i32 %47 to i64
%49 = mul i64 %48, 1
%50 = trunc i64 %49 to i32
%51 = call i8* @malloc(i32 %50)
store i8* %51, i8** %12
%52 = load i8*, i8** %12
%53 = call i32 @memset(i8* %52, i8 signext 0, i32 8)
%54 = load i8*, i8** %12
%55 = load i32, i32* %9
%56 = load i32*, i32** %5
%57 = call i32 @fread(i8* %54, i32 1, i32 %55, i32* %56)
%58 = load i8*, i8** %12
store i8* %58, i8** %10
%59 = load i8*, i8** %10
%60 = getelementptr inbounds i8, i8* %59, i64 4
store i8* %60, i8** %10
%61 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%62 = load i8*, i8** %10
%63 = call i32 @copy_cbyc(i8* %61, i8* %62, i32 2)
%64 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 2
store i8 0, i8* %64
%65 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%66 = call i32 @to_intconvertor(i8* %65)
store i32 %66, i32* %8
%67 = load i32, i32* %8
%68 = load i32, i32* %3
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %72
70: ; preds = %35
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.5, i64 0, i64 0))
br label %84
72: ; preds = %35
%73 = load i8*, i8** %12
%74 = load i32, i32* %9
%75 = load i32*, i32** %6
%76 = call i32 @fwrite(i8* %73, i32 1, i32 %74, i32* %75)
%77 = load i8*, i8** %12
%78 = call i32 @free(i8* %77)
%79 = load i32, i32* %9
%80 = zext i32 %79 to i64
%81 = load i64, i64* %14
%82 = sub i64 %81, %80
store i64 %82, i64* %14
br label %83
83: ; preds = %72
br label %32
84: ; preds = %70, %32
%85 = load i8*, i8** %4
store i8* %85, i8** %16
%86 = load i8*, i8** %16
%87 = getelementptr inbounds i8, i8* %86, i64 2
store i8* %87, i8** %16
%88 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%89 = load i8*, i8** %16
%90 = call i32 @copy_cbyc(i8* %88, i8* %89, i32 2)
%91 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%92 = call i32 @to_intconvertor(i8* %91)
store i32 %92, i32* %15
%93 = load i8*, i8** %4
%94 = load i32, i32* %15
%95 = load i32*, i32** %6
%96 = call i32 @fwrite(i8* %93, i32 1, i32 %94, i32* %95)
br label %97
97: ; preds = %140, %84
%98 = load i64, i64* %14
%99 = icmp ne i64 %98, 0
br i1 %99, label %100, label %141
100: ; preds = %97
%101 = load i32*, i32** %5
%102 = load i32, i32* @SEEK_CUR
%103 = call i32 @fseek(i32* %101, i32 2, i32 %102)
%104 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%105 = load i32*, i32** %5
%106 = call i32 @fread(i8* %104, i32 1, i32 2, i32* %105)
%107 = load i32*, i32** %5
%108 = load i32, i32* @SEEK_CUR
%109 = call i32 @fseek(i32* %107, i32 -4, i32 %108)
%110 = getelementptr inbounds [2 x i8], [2 x i8]* %13, i64 0, i64 0
%111 = call i32 @to_intconvertor(i8* %110)
store i32 %111, i32* %9
%112 = load i32, i32* %9
%113 = zext i32 %112 to i64
%114 = mul i64 %113, 1
%115 = trunc i64 %114 to i32
%116 = call i8* @malloc(i32 %115)
store i8* %116, i8** %12
%117 = load i8*, i8** %12
%118 = call i32 @memset(i8* %117, i8 signext 0, i32 8)
%119 = load i8*, i8** %12
%120 = load i32, i32* %9
%121 = load i32*, i32** %5
%122 = call i32 @fread(i8* %119, i32 1, i32 %120, i32* %121)
%123 = load i8*, i8** %12
%124 = load i8*, i8** %4
%125 = load i32, i32* %9
%126 = call i32 @ncmp_cbyc(i8* %123, i8* %124, i32 %125)
%127 = icmp ne i32 %126, 0
br i1 %127, label %129, label %128
128: ; preds = %100
br label %141
129: ; preds = %100
%130 = load i8*, i8** %4
%131 = load i32, i32* %9
%132 = load i32*, i32** %6
%133 = call i32 @fwrite(i8* %130, i32 1, i32 %131, i32* %132)
%134 = load i8*, i8** %12
%135 = call i32 @free(i8* %134)
%136 = load i32, i32* %9
%137 = zext i32 %136 to i64
%138 = load i64, i64* %14
%139 = sub i64 %138, %137
store i64 %139, i64* %14
br label %140
140: ; preds = %129
br label %97
141: ; preds = %128, %97
%142 = load i32*, i32** %5
%143 = call i32 @fclose(i32* %142)
%144 = load i32*, i32** %6
%145 = call i32 @fclose(i32* %144)
%146 = call i64 @remove(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%147 = icmp ne i64 %146, 0
br i1 %147, label %148, label %150
148: ; preds = %141
%149 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %150
150: ; preds = %148, %141
%151 = call i32 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 %151, i32* %7
%152 = load i32, i32* %7
%153 = icmp eq i32 %152, 0
br i1 %153, label %154, label %156
154: ; preds = %150
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %158
156: ; preds = %150
%157 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %158
158: ; preds = %156, %154
br label %161
159: ; preds = %2
%160 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %161
161: ; preds = %159, %158
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"cfg.bin\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [9 x i8] c"ncfg.bin\00"
@.str.3 = [3 x i8] c"wb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [41 x i8] c"BEFORE REMOVAL OF OLDFRAME FILE LEN %ld\0A\00"
@SEEK_CUR = global i32 0
@.str.6 = [20 x i8] c"Error deleting file\00"
@.str.8 = [21 x i8] c"Error renaming file\0A\00"
@str = [26 x i8] c"File successfully renamed\00"
@str.9 = [56 x i8] c"IDcode of new cfg MATCHED with old cfg in file cfg.bin!\00"
define void @remove_old_cfg(i32 %0, i8* %1) {
%3 = alloca [3 x i8]
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp eq i32* %7, null
br i1 %9, label %83, label %10
10: ; preds = %2
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %7, i32 0, i32 %11)
%13 = tail call i64 @ftell(i32* %7)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %7, i32 0, i32 %14)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i64 %13)
%17 = icmp eq i64 %13, 0
br i1 %17, label %43, label %18
18: ; preds = %10
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
br label %20
20: ; preds = %18, %37
%21 = phi i64 [ %13, %18 ], [ %41, %37 ]
%22 = load i32, i32* @SEEK_CUR
%23 = call i32 @fseek(i32* %7, i32 2, i32 %22)
%24 = call i32 @fread(i8* %6, i32 1, i32 2, i32* %7)
%25 = load i32, i32* @SEEK_CUR
%26 = call i32 @fseek(i32* %7, i32 -4, i32 %25)
%27 = call i32 @to_intconvertor(i8* %6)
%28 = call i8* @malloc(i32 %27)
%29 = call i32 @memset(i8* %28, i8 signext 0, i32 8)
%30 = call i32 @fread(i8* %28, i32 1, i32 %27, i32* %7)
%31 = getelementptr inbounds i8, i8* %28, i64 4
%32 = call i32 @copy_cbyc(i8* %5, i8* %31, i32 2)
store i8 0, i8* %19
%33 = call i32 @to_intconvertor(i8* %5)
%34 = icmp eq i32 %33, %0
br i1 %34, label %35, label %37
35: ; preds = %20
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.9, i64 0, i64 0))
br label %43
37: ; preds = %20
%38 = zext i32 %27 to i64
%39 = call i32 @fwrite(i8* %28, i32 1, i32 %27, i32* %8)
%40 = call i32 @free(i8* %28)
%41 = sub i64 %21, %38
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %20
43: ; preds = %37, %10, %35
%44 = phi i64 [ %21, %35 ], [ 0, %10 ], [ 0, %37 ]
%45 = getelementptr inbounds i8, i8* %1, i64 2
%46 = call i32 @copy_cbyc(i8* %6, i8* %45, i32 2)
%47 = call i32 @to_intconvertor(i8* %6)
%48 = call i32 @fwrite(i8* %1, i32 1, i32 %47, i32* %8)
%49 = icmp eq i64 %44, 0
br i1 %49, label %69, label %50
50: ; preds = %43, %63
%51 = phi i64 [ %67, %63 ], [ %44, %43 ]
%52 = load i32, i32* @SEEK_CUR
%53 = call i32 @fseek(i32* %7, i32 2, i32 %52)
%54 = call i32 @fread(i8* %6, i32 1, i32 2, i32* %7)
%55 = load i32, i32* @SEEK_CUR
%56 = call i32 @fseek(i32* %7, i32 -4, i32 %55)
%57 = call i32 @to_intconvertor(i8* %6)
%58 = call i8* @malloc(i32 %57)
%59 = call i32 @memset(i8* %58, i8 signext 0, i32 8)
%60 = call i32 @fread(i8* %58, i32 1, i32 %57, i32* %7)
%61 = call i32 @ncmp_cbyc(i8* %58, i8* %1, i32 %57)
%62 = icmp eq i32 %61, 0
br i1 %62, label %69, label %63
63: ; preds = %50
%64 = zext i32 %57 to i64
%65 = call i32 @fwrite(i8* %1, i32 1, i32 %57, i32* %8)
%66 = call i32 @free(i8* %58)
%67 = sub i64 %51, %64
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %50
69: ; preds = %63, %50, %43
%70 = call i32 @fclose(i32* %7)
%71 = call i32 @fclose(i32* %8)
%72 = call i64 @remove(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %69
%75 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
br label %76
76: ; preds = %74, %69
%77 = call i32 @rename(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %85
81: ; preds = %76
%82 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %85
83: ; preds = %2
%84 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %85
85: ; preds = %79, %81, %83
ret void
}