#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 ccnl_switch_prependCodeVal(unsigned int, int *, unsigned char *);
int ccnl_switch_prependCoding(unsigned int code, int *offset,
                              unsigned char *buf) {
  int len;
  if (*offset < 2)
    return -1;
  len = ccnl_switch_prependCodeVal(code, offset, buf);
  if (len < 0 || *offset < 1)
    return -1;
  *offset -= 1;
  buf[*offset] = 0x80;
  return len + 1;
}


x86 assembly (clang, -O0):
<ccnl_switch_prependCoding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x2,(%rax)
jge    113c <ccnl_switch_prependCoding+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <ccnl_switch_prependCoding+0x85>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <ccnl_switch_prependCodeVal@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1166 <ccnl_switch_prependCoding+0x56>
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jge    1172 <ccnl_switch_prependCoding+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <ccnl_switch_prependCoding+0x85>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x80,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ccnl_switch_prependCoding>:
push   %rbp
push   %r14
push   %rbx
mov    $0xffffffff,%ebp
cmpl   $0x2,(%rsi)
jl     1142 <ccnl_switch_prependCoding+0x32>
mov    %rdx,%r14
mov    %rsi,%rbx
call   1030 <ccnl_switch_prependCodeVal@plt>
test   %eax,%eax
js     1142 <ccnl_switch_prependCoding+0x32>
mov    (%rbx),%ecx
test   %ecx,%ecx
jle    1142 <ccnl_switch_prependCoding+0x32>
add    $0xffffffff,%ecx
mov    %ecx,(%rbx)
movb   $0x80,(%r14,%rcx,1)
add    $0x1,%eax
mov    %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ccnl_switch_prependCoding(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%9 = load i32*, i32** %6
%10 = load i32, i32* %9
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %36
13: ; preds = %3
%14 = load i32, i32* %5
%15 = load i32*, i32** %6
%16 = load i8*, i8** %7
%17 = call i32 @ccnl_switch_prependCodeVal(i32 %14, i32* %15, i8* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %13
%21 = load i32*, i32** %6
%22 = load i32, i32* %21
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %20, %13
store i32 -1, i32* %4
br label %36
25: ; preds = %20
%26 = load i32*, i32** %6
%27 = load i32, i32* %26
%28 = sub nsw i32 %27, 1
store i32 %28, i32* %26
%29 = load i8*, i8** %7
%30 = load i32*, i32** %6
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 -128, i8* %33
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %36
36: ; preds = %25, %24, %12
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @ccnl_switch_prependCoding(i32 %0, i32* %1, i8* %2) {
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 2
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = tail call i32 @ccnl_switch_prependCodeVal(i32 %0, i32* %1, i8* %2)
%8 = icmp slt i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = add nsw i32 %10, -1
store i32 %13, i32* %1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %2, i64 %14
store i8 -128, i8* %15
%16 = add nuw nsw i32 %7, 1
br label %17
17: ; preds = %6, %9, %3, %12
%18 = phi i32 [ %16, %12 ], [ -1, %3 ], [ -1, %9 ], [ -1, %6 ]
ret i32 %18
}