#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(int);
int /*<<< orphan*/ printf(char *, int, ...);
void setModel(int model, int position, int *a) {
  if (a[position] == -1)
    a[position] = model;
  else {
    printf("ERROR trying to assign model %d to position %d \n", model,
           position);
    printf("while already model %d has been assigned to this position\n",
           a[position]);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<setModel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
jne    1157 <setModel+0x37>
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    118e <setModel+0x6e>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setModel>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %edi,%eax
movslq %esi,%rbx
cmpl   $0xffffffff,(%rdx,%rbx,4)
jne    113e <setModel+0x1e>
mov    %eax,(%r14,%rbx,4)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xebb(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r14,%rbx,4),%esi
lea    0xed6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"ERROR trying to assign model %d to position %d \0A\00"
@.str.1 = [59 x i8] c"while already model %d has been assigned to this position\0A\00"
define void @setModel(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32*, i32** %6
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %7, i64 %9
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = load i32, i32* %4
%15 = load i32*, i32** %6
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
store i32 %14, i32* %18
br label %30
19: ; preds = %3
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
%23 = load i32*, i32** %6
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"ERROR trying to assign model %d to position %d \0A\00"
@.str.1 = [59 x i8] c"while already model %d has been assigned to this position\0A\00"
define void @setModel(i32 %0, i32 %1, i32* nocapture %2) {
%4 = sext i32 %1 to i64
%5 = getelementptr inbounds i32, i32* %2, i64 %4
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %3
store i32 %0, i32* %5
ret void
9: ; preds = %3
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%11 = load i32, i32* %5
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i32 @exit(i32 -1)
unreachable
}