#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ system(char *);
void write_flash_kernel_version(char *file, int offset) {
  char cmd[512];
  char buf[512];
  FILE *fp = fopen("/proc/version", "r");
  fgets(buf, 512, fp);
  fclose(fp);
  sprintf(cmd, "nvram_set 2860 old_firmware \"%s\"", buf);
  system(cmd);
}


x86 assembly (clang, -O0):
<write_flash_kernel_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x210(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <system@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_flash_kernel_version>:
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xe9f(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe7e(%rip),%rsi
lea    0x200(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/version\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"nvram_set 2860 old_firmware \22%s\22\00"
define void @write_flash_kernel_version(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca i32*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%10 = load i32*, i32** %7
%11 = call i32 @fgets(i8* %9, i32 512, i32* %10)
%12 = load i32*, i32** %7
%13 = call i32 @fclose(i32* %12)
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%18 = call i32 @system(i8* %17)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/version\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"nvram_set 2860 old_firmware \22%s\22\00"
define void @write_flash_kernel_version(i8* nocapture readnone %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @fgets(i8* %6, i32 512, i32* %7)
%9 = call i32 @fclose(i32* %7)
%10 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%11 = call i32 @system(i8* %5)
ret void
}