#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int safe_assign(char *token, size_t size, int c, int *i) {
  if ((*i + 1) < size) {
    *(token + (*i)++) = c;
  } else {
    fprintf(stderr, "Error: token char array is too small!\n");
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<safe_assign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
cmp    -0x18(%rbp),%rax
jae    115d <safe_assign+0x4d>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rsi
mov    (%rsi),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    %edi,(%rsi)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1183 <safe_assign+0x73>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <safe_assign+0x7f>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_assign>:
push   %rax
movslq (%rcx),%r8
lea    0x1(%r8),%rax
cmp    %rsi,%rax
jae    112c <safe_assign+0x1c>
mov    %eax,(%rcx)
mov    %dl,(%rdi,%r8,1)
mov    0x2ea6(%rip),%rax
jmp    1148 <safe_assign+0x38>
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Error: token char array is too small!\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @safe_assign(i8* %0, i64 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%10 = load i32*, i32** %9
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = load i64, i64* %7
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %4
%17 = load i32, i32* %8
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %6
%20 = load i32*, i32** %9
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %20
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
store i8 %18, i8* %24
br label %29
25: ; preds = %4
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %5
br label %31
29: ; preds = %16
%30 = load i32, i32* @EXIT_SUCCESS
store i32 %30, i32* %5
br label %31
31: ; preds = %29, %25
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Error: token char array is too small!\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @safe_assign(i8* nocapture writeonly %0, i64 %1, i32 %2, i32* nocapture %3) {
%5 = load i32, i32* %3
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = icmp ult i64 %7, %1
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = trunc i32 %2 to i8
store i32 %6, i32* %3
%11 = sext i32 %5 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 %10, i8* %12
br label %16
13: ; preds = %4
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %9, %13
%17 = phi i32* [ @EXIT_SUCCESS, %9 ], [ @EXIT_FAILURE, %13 ]
%18 = load i32, i32* %17
ret i32 %18
}