#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*/ _gcoapMsg_putBuffer(unsigned char *, int);
int /*<<< orphan*/ _gcoapMsg_putByte(int);
int strlen(char *);
void encodeOption(int opt, int prevopt, char *value) {
  int sz = strlen(value);
  if (sz < 15)
    _gcoapMsg_putByte(((opt - prevopt) << 4) + sz);
  else {
    _gcoapMsg_putByte(((opt - prevopt) << 4) + 0x0f);
    _gcoapMsg_putByte(sz - 15);
  }
  _gcoapMsg_putBuffer((unsigned char *)value, sz);
}


x86 assembly (clang, -O0):
<encodeOption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xf,-0x14(%rbp)
jge    116e <encodeOption+0x3e>
mov    -0x4(%rbp),%edi
sub    -0x8(%rbp),%edi
shl    $0x4,%edi
add    -0x14(%rbp),%edi
call   1050 <_gcoapMsg_putByte@plt>
jmp    118a <encodeOption+0x5a>
mov    -0x4(%rbp),%edi
sub    -0x8(%rbp),%edi
shl    $0x4,%edi
add    $0xf,%edi
call   1050 <_gcoapMsg_putByte@plt>
mov    -0x14(%rbp),%edi
sub    $0xf,%edi
call   1050 <_gcoapMsg_putByte@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <_gcoapMsg_putBuffer@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encodeOption>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebx
mov    %rdx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
sub    %r15d,%ebx
shl    $0x4,%ebx
cmp    $0xf,%eax
jl     1163 <encodeOption+0x33>
or     $0xf,%ebx
mov    %ebx,%edi
call   1050 <_gcoapMsg_putByte@plt>
mov    $0xfffffff1,%ebx
mov    %ebp,%edi
add    %ebx,%edi
call   1050 <_gcoapMsg_putByte@plt>
mov    %r14,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <_gcoapMsg_putBuffer@plt>

LLVM IR (-O0):
define void @encodeOption(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 15
br i1 %11, label %12, label %20
12: ; preds = %3
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = sub nsw i32 %13, %14
%16 = shl i32 %15, 4
%17 = load i32, i32* %7
%18 = add nsw i32 %16, %17
%19 = call i32 @_gcoapMsg_putByte(i32 %18)
br label %30
20: ; preds = %3
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = sub nsw i32 %21, %22
%24 = shl i32 %23, 4
%25 = add nsw i32 %24, 15
%26 = call i32 @_gcoapMsg_putByte(i32 %25)
%27 = load i32, i32* %7
%28 = sub nsw i32 %27, 15
%29 = call i32 @_gcoapMsg_putByte(i32 %28)
br label %30
30: ; preds = %20, %12
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = call i32 @_gcoapMsg_putBuffer(i8* %31, i32 %32)
ret void
}

LLVM IR (-O2):
define void @encodeOption(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = icmp slt i32 %4, 15
%6 = sub nsw i32 %0, %1
%7 = shl i32 %6, 4
br i1 %5, label %11, label %8
8: ; preds = %3
%9 = or i32 %7, 15
%10 = tail call i32 @_gcoapMsg_putByte(i32 %9)
br label %11
11: ; preds = %3, %8
%12 = phi i32 [ -15, %8 ], [ %7, %3 ]
%13 = add nsw i32 %4, %12
%14 = tail call i32 @_gcoapMsg_putByte(i32 %13)
%15 = tail call i32 @_gcoapMsg_putBuffer(i8* %2, i32 %4)
ret void
}