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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
void set_hint_fzx2(FILE *fp, unsigned char *buf, int argc, char *argv[]) {
  uint32_t v;
  unsigned short top;
  if (argc == 2) {
    printf("Fuzix binary hints %02X bytes.\n", buf[5]);
    return;
  }
  if (sscanf(argv[2], "%u", &v) != 1 || v > 255) {
    fprintf(stderr, "%s: invalid set_hint value '%s'.\n", argv[0], argv[2]);
    exit(1);
  }
  buf[5] = v;
  rewind(fp);
  if (fwrite(buf, 16, 1, fp) != 1) {
    fprintf(stderr, "%s: write error.\n", argv[0]);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<set_hint_fzx2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    119a <set_hint_fzx2+0x3a>
mov    -0x10(%rbp),%rax
lea    0xe74(%rip),%rdi
movzbl 0x5(%rax),%esi
call   1030 <printf@plt>
jmp    1255 <set_hint_fzx2+0xf5>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe77(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11c8 <set_hint_fzx2+0x68>
cmpl   $0xff,-0x24(%rbp)
jle    11f8 <set_hint_fzx2+0x98>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x8(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x10,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
je     1255 <set_hint_fzx2+0xf5>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_hint_fzx2>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edx
jne    118a <set_hint_fzx2+0x2a>
movzbl 0x5(%rbx),%esi
lea    0xe84(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printf@plt>
mov    %rcx,%r14
mov    %rdi,%r15
mov    0x10(%rcx),%rdi
lea    0xe85(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11e4 <set_hint_fzx2+0x84>
mov    0xc(%rsp),%eax
cmp    $0x100,%eax
jge    11e4 <set_hint_fzx2+0x84>
mov    %al,0x5(%rbx)
mov    %r15,%rdi
call   1040 <rewind@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
cmp    $0x1,%eax
jne    120c <set_hint_fzx2+0xac>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
mov    0x10(%r14),%rcx
lea    0xe28(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Fuzix binary hints %02X bytes.\0A\00"
@.str.1 = [3 x i8] c"%u\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"%s: invalid set_hint value '%s'.\0A\00"
@.str.3 = [18 x i8] c"%s: write error.\0A\00"
define void @set_hint_fzx2(i32* %0, i8* %1, i32 %2, i8** %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i16
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8** %3, i8*** %8
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 5
%16 = load i8, i8* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8 zeroext %16)
br label %55
18: ; preds = %4
%19 = load i8**, i8*** %8
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%23 = icmp ne i32 %22, 1
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = load i32, i32* %9
%26 = icmp sgt i32 %25, 255
br i1 %26, label %27, label %37
27: ; preds = %24, %18
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %8
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = load i8**, i8*** %8
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %31, i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %24
%38 = load i32, i32* %9
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 5
store i8 %39, i8* %41
%42 = load i32*, i32** %5
%43 = call i32 @rewind(i32* %42)
%44 = load i8*, i8** %6
%45 = load i32*, i32** %5
%46 = call i32 @fwrite(i8* %44, i32 16, i32 1, i32* %45)
%47 = icmp ne i32 %46, 1
br i1 %47, label %48, label %55
48: ; preds = %37
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %8
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %13, %37
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Fuzix binary hints %02X bytes.\0A\00"
@.str.1 = [3 x i8] c"%u\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"%s: invalid set_hint value '%s'.\0A\00"
@.str.3 = [18 x i8] c"%s: write error.\0A\00"
define void @set_hint_fzx2(i32* nocapture %0, i8* nocapture %1, i32 %2, i8** nocapture %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = icmp eq i32 %2, 2
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %1, i64 5
%10 = load i8, i8* %9
%11 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8 zeroext %10)
br label %37
12: ; preds = %4
%13 = getelementptr inbounds i8*, i8** %3, i64 2
%14 = load i8*, i8** %13
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%16 = icmp ne i32 %15, 1
%17 = load i32, i32* %5
%18 = icmp sgt i32 %17, 255
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = load i8*, i8** %13
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %22, i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %12
%27 = trunc i32 %17 to i8
%28 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %27, i8* %28
%29 = call i32 @rewind(i32* %0)
%30 = call i32 @fwrite(i8* %1, i32 16, i32 1, i32* %0)
%31 = icmp eq i32 %30, 1
br i1 %31, label %37, label %32
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %3
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26, %8
ret void
}