#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_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ system(char *);
char *tempnam(char *, char *);
int /*<<< orphan*/ unlink(char *);
void import(char *filename, int offset, int len) {
  char cmd[4096];
  char data;
  FILE *fp, *src;
  char *pname = tempnam("/var", "set");
  snprintf(cmd, 4096, "cp %s /var/tmpcgi", filename);
  system(cmd);
  if (!(fp = fopen(pname, "w+"))) {
    return;
  }
  if (!(src = fopen(filename, "r"))) {
    fclose(fp);
    return;
  }
  if (fseek(src, offset, SEEK_SET) == -1) {
    printf("fseek error\n");
  }
  while (len > 0) {
    if (!fread(&data, 1, 1, src))
      break;
    fwrite(&data, 1, 1, fp);
    len--;
  }
  fclose(fp);
  fclose(src);
  system("ralink_init clear 2860");
  snprintf(cmd, 4096, "ralink_init renew 2860 %s", pname);
  system(cmd);
  unlink(pname);
}


x86 assembly (clang, -O0):
<import>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xe44(%rip),%rdi
lea    0xe42(%rip),%rsi
call   1090 <tempnam@plt>
mov    %rax,-0x1030(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1000,%esi
lea    0xe23(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x1010(%rbp),%rdi
call   1060 <system@plt>
mov    -0x1030(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x1020(%rbp)
cmp    $0x0,%rax
jne    1220 <import+0x80>
jmp    1339 <import+0x199>
mov    -0x8(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
jne    1252 <import+0xb2>
mov    -0x1020(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1339 <import+0x199>
mov    -0x1028(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
cmp    $0xffffffff,%eax
jne    127f <import+0xdf>
lea    0xda4(%rip),%rdi
call   1070 <printf@plt>
jmp    1284 <import+0xe4>
cmpl   $0x0,-0x10(%rbp)
jle    12de <import+0x13e>
mov    -0x1028(%rbp),%rcx
lea    -0x1011(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x0,%eax
jne    12b6 <import+0x116>
jmp    12de <import+0x13e>
mov    -0x1020(%rbp),%rcx
lea    -0x1011(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10c0 <fwrite@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1284 <import+0xe4>
mov    -0x1020(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1028(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd2e(%rip),%rdi
call   1060 <system@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x1030(%rbp),%rcx
mov    $0x1000,%esi
lea    0xd26(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x1010(%rbp),%rdi
call   1060 <system@plt>
mov    -0x1030(%rbp),%rdi
call   1030 <unlink@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<import>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %edx,%ebp
mov    %esi,%r12d
mov    %rdi,%r13
lea    0xe40(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   10a0 <tempnam@plt>
mov    %rax,%r14
lea    0xe33(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r13,%rcx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
lea    0xe21(%rip),%rsi
mov    %r14,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12e0 <import+0x140>
mov    %rax,%r15
lea    0xdee(%rip),%rsi
mov    %r13,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12d8 <import+0x138>
mov    %rax,%rbx
mov    0x2db0(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r12d,%esi
call   10b0 <fseek@plt>
cmp    $0xffffffff,%eax
jne    124e <import+0xae>
lea    0xe06(%rip),%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
jle    128e <import+0xee>
add    $0x1,%ebp
lea    0xf(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %eax,%eax
je     128e <import+0xee>
movsbl 0xf(%rsp),%edi
mov    %r15,%rsi
call   1090 <fputc@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jg     1260 <import+0xc0>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xd79(%rip),%rdi
call   1070 <system@plt>
lea    0xd84(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
mov    %r14,%rcx
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1070 <system@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
jmp    12e0 <import+0x140>
mov    %r15,%rdi
call   1060 <fclose@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"/var\00"
@.str.1 = [4 x i8] c"set\00"
@.str.2 = [18 x i8] c"cp %s /var/tmpcgi\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.5 = [13 x i8] c"fseek error\0A\00"
@.str.6 = [23 x i8] c"ralink_init clear 2860\00"
@.str.7 = [26 x i8] c"ralink_init renew 2860 %s\00"
define void @import(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca i8
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = call i8* @tempnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %11
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = call i32 @snprintf(i8* %13, i32 4096, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%17 = call i32 @system(i8* %16)
%18 = load i8*, i8** %11
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %19, i32** %9
%20 = icmp ne i32* %19, null
br i1 %20, label %22, label %21
21: ; preds = %3
br label %64
22: ; preds = %3
%23 = load i8*, i8** %4
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %24, i32** %10
%25 = icmp ne i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = load i32*, i32** %9
%28 = call i32 @fclose(i32* %27)
br label %64
29: ; preds = %22
%30 = load i32*, i32** %10
%31 = load i32, i32* %5
%32 = load i32, i32* @SEEK_SET
%33 = call i32 @fseek(i32* %30, i32 %31, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
br label %38
38: ; preds = %46, %37
%39 = load i32, i32* %6
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %51
41: ; preds = %38
%42 = load i32*, i32** %10
%43 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %41
br label %51
46: ; preds = %41
%47 = load i32*, i32** %9
%48 = call i32 @fwrite(i8* %8, i32 1, i32 1, i32* %47)
%49 = load i32, i32* %6
%50 = add nsw i32 %49, -1
store i32 %50, i32* %6
br label %38
51: ; preds = %45, %38
%52 = load i32*, i32** %9
%53 = call i32 @fclose(i32* %52)
%54 = load i32*, i32** %10
%55 = call i32 @fclose(i32* %54)
%56 = call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%57 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%58 = load i8*, i8** %11
%59 = call i32 @snprintf(i8* %57, i32 4096, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %58)
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%61 = call i32 @system(i8* %60)
%62 = load i8*, i8** %11
%63 = call i32 @unlink(i8* %62)
br label %64
64: ; preds = %51, %26, %21
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"/var\00"
@.str.1 = [4 x i8] c"set\00"
@.str.2 = [18 x i8] c"cp %s /var/tmpcgi\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.6 = [23 x i8] c"ralink_init clear 2860\00"
@.str.7 = [26 x i8] c"ralink_init renew 2860 %s\00"
@str = [12 x i8] c"fseek error\00"
define void @import(i8* %0, i32 %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = alloca i8
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @tempnam(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @snprintf(i8* %6, i32 4096, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%9 = call i32 @system(i8* %6)
%10 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %42, label %12
12: ; preds = %3
%13 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @fclose(i32* %10)
br label %42
17: ; preds = %12
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32* %13, i32 %1, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = icmp sgt i32 %2, 0
br i1 %24, label %25, label %35
25: ; preds = %23, %29
%26 = phi i32 [ %33, %29 ], [ %2, %23 ]
%27 = call i32 @fread(i8* %5, i32 1, i32 1, i32* %13)
%28 = icmp eq i32 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %25
%30 = load i8, i8* %5
%31 = sext i8 %30 to i32
%32 = call i32 @fputc(i32 %31, i32* %10)
%33 = add nsw i32 %26, -1
%34 = icmp sgt i32 %26, 1
br i1 %34, label %25, label %35
35: ; preds = %29, %25, %23
%36 = call i32 @fclose(i32* %10)
%37 = call i32 @fclose(i32* %13)
%38 = call i32 @system(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%39 = call i32 @snprintf(i8* %6, i32 4096, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %7)
%40 = call i32 @system(i8* %6)
%41 = call i32 @unlink(i8* %7)
br label %42
42: ; preds = %3, %35, %15
ret void
}