#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ report_error(char *);
int /*<<< orphan*/ stderr;
void set_ram(unsigned char *ram, int *pos, int val) {
  if (val < 0 || val > 255) {
    fprintf(stderr, "Internal compiler error 2.\n");
    exit(EXIT_FAILURE);
  }
  if (*pos == 256) {
    report_error("Program too large");
  }
  if (*pos < 256) {
    ram[*pos] = (unsigned char)val;
  }
  (*pos)++;
}


x86 assembly (clang, -O0):
<set_ram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     115a <set_ram+0x2a>
cmpl   $0xff,-0x14(%rbp)
jle    117d <set_ram+0x4d>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x100,(%rax)
jne    1199 <set_ram+0x69>
lea    0xe88(%rip),%rdi
call   1040 <report_error@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x100,(%rax)
jge    11bc <set_ram+0x8c>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ram>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x100,%edx
jae    1174 <set_ram+0x44>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%eax
cmp    $0x100,%eax
jne    115b <set_ram+0x2b>
lea    0xec8(%rip),%rdi
call   1040 <report_error@plt>
mov    (%rbx),%eax
cmp    $0xff,%eax
jg     116a <set_ram+0x3a>
cltq
mov    %bpl,(%r14,%rax,1)
mov    (%rbx),%eax
add    $0x1,%eax
mov    %eax,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Internal compiler error 2.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"Program too large\00"
define void @set_ram(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp slt i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = load i32, i32* %6
%11 = icmp sgt i32 %10, 255
br i1 %11, label %12, label %17
12: ; preds = %9, %3
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %9
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = icmp eq i32 %19, 256
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @report_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = load i32*, i32** %5
%25 = load i32, i32* %24
%26 = icmp slt i32 %25, 256
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i32, i32* %6
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %4
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
br label %35
35: ; preds = %27, %23
%36 = load i32*, i32** %5
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
store i32 %38, i32* %36
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Internal compiler error 2.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"Program too large\00"
define void @set_ram(i8* nocapture writeonly %0, i32* nocapture %1, i32 %2) {
%4 = icmp ugt i32 %2, 255
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %3
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 256
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @report_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %1
br label %16
16: ; preds = %13, %10
%17 = phi i32 [ %15, %13 ], [ %11, %10 ]
%18 = icmp slt i32 %17, 256
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = trunc i32 %2 to i8
%21 = sext i32 %17 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 %20, i8* %22
%23 = load i32, i32* %1
br label %24
24: ; preds = %19, %16
%25 = phi i32 [ %23, %19 ], [ %17, %16 ]
%26 = add nsw i32 %25, 1
store i32 %26, i32* %1
ret void
}