#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  char *image = NULL;
  int major = 0;
  int minor = 0;
  FILE *bzImage = NULL;
  if (argc < 4) {
    usage();
    return 1;
  }
  image = argv[1];
  major = atoi(argv[2]);
  minor = atoi(argv[3]);
  bzImage = fopen(image, "r+");
  if (!bzImage) {
    printf("error opening bzImage\n");
    return -1;
  }
  fseek(bzImage, 0x1FC, SEEK_SET);
  fwrite(&minor, sizeof(char), 1, bzImage);
  fwrite(&major, sizeof(char), 1, bzImage);
  fclose(bzImage);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11c1 <main+0x51>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1273 <main+0x103>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1224 <main+0xb4>
lea    0xdf0(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <main+0x103>
mov    -0x28(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%edx
mov    $0x1fc,%esi
call   1050 <fseek@plt>
mov    -0x28(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
mov    -0x28(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1090 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jg     118d <main+0x1d>
xor    %eax,%eax
call   1070 <usage@plt>
mov    $0x1,%eax
jmp    120e <main+0x9e>
mov    %rsi,%rbx
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r15d
lea    0xe4d(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fd <main+0x8d>
mov    %rax,%rbx
mov    0x2e16(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x1fc,%esi
call   1060 <fseek@plt>
movsbl %r15b,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
movsbl %r14b,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    120e <main+0x9e>
lea    0xdff(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"r+\00"
@.str.1 = [23 x i8] c"error opening bzImage\0A\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32* null, i32** %9
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 4
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @usage()
store i32 1, i32* %3
br label %42
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %8
%26 = load i8*, i8** %6
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %9
%28 = load i32*, i32** %9
%29 = icmp ne i32* %28, null
br i1 %29, label %32, label %30
30: ; preds = %14
%31 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
32: ; preds = %14
%33 = load i32*, i32** %9
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @fseek(i32* %33, i32 508, i32 %34)
%36 = load i32*, i32** %9
%37 = call i32 @fwrite(i32* %8, i32 1, i32 1, i32* %36)
%38 = load i32*, i32** %9
%39 = call i32 @fwrite(i32* %7, i32 1, i32 1, i32* %38)
%40 = load i32*, i32** %9
%41 = call i32 @fclose(i32* %40)
store i32 0, i32* %3
br label %42
42: ; preds = %32, %30, %12
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"r+\00"
@SEEK_SET = global i32 0
@str = [22 x i8] c"error opening bzImage\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %29
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %6
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %29
19: ; preds = %6
%20 = load i32, i32* @SEEK_SET
%21 = tail call i32 @fseek(i32* %15, i32 508, i32 %20)
%22 = shl i32 %14, 24
%23 = ashr exact i32 %22, 24
%24 = tail call i32 @fputc(i32 %23, i32* %15)
%25 = shl i32 %11, 24
%26 = ashr exact i32 %25, 24
%27 = tail call i32 @fputc(i32 %26, i32* %15)
%28 = tail call i32 @fclose(i32* %15)
br label %29
29: ; preds = %19, %17, %4
%30 = phi i32 [ 1, %4 ], [ 0, %19 ], [ -1, %17 ]
ret i32 %30
}