#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 */
typedef void *int16_t;

/* Variables and functions */
void *htons(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *add_option(char *cp, int tag, char *optname, char *optval) {
  int n;
  union {
    int16_t s;
    char c[2];
  } u;
  *cp++ = tag;
  n = strlen(optname);
  u.s = htons(n);
  *cp++ = u.c[0];
  *cp++ = u.c[1];
  strcpy(cp, optname);
  cp += n;
  n = strlen(optval);
  u.s = htons(n);
  *cp++ = u.c[0];
  *cp++ = u.c[1];
  strcpy(cp, optval);
  return cp + n;
}


x86 assembly (clang, -O0):
<add_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x2f(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <htons@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x2f(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_option>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%rbx
mov    %sil,(%rdi)
mov    %rdx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <htons@plt>
lea    0x3(%rbx),%rdi
mov    %ax,0x1(%rbx)
mov    %r15,%rsi
call   1030 <strcpy@plt>
movslq %ebp,%rbp
lea    (%rbx,%rbp,1),%r12
add    $0x3,%r12
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %eax,%edi
call   1050 <htons@plt>
lea    (%rbx,%rbp,1),%rdi
add    $0x5,%rdi
mov    %ax,0x3(%rbx,%rbp,1)
mov    %r14,%rsi
call   1030 <strcpy@plt>
movslq %r15d,%rax
add    %r12,%rax
add    $0x2,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.anon = type { i8* }
define i8* @add_option(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca %union.anon
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i32, i32* %6
%12 = trunc i32 %11 to i8
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
store i8 %12, i8* %13
%15 = load i8*, i8** %7
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = call i8* @htons(i32 %17)
%19 = bitcast %union.anon* %10 to i8**
store i8* %18, i8** %19
%20 = bitcast %union.anon* %10 to [2 x i8]*
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %20, i64 0, i64 0
%22 = load i8, i8* %21
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
store i8 %22, i8* %23
%25 = bitcast %union.anon* %10 to [2 x i8]*
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %25, i64 0, i64 1
%27 = load i8, i8* %26
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
store i8 %27, i8* %28
%30 = load i8*, i8** %5
%31 = load i8*, i8** %7
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i32, i32* %9
%34 = load i8*, i8** %5
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8* %36, i8** %5
%37 = load i8*, i8** %8
%38 = call i32 @strlen(i8* %37)
store i32 %38, i32* %9
%39 = load i32, i32* %9
%40 = call i8* @htons(i32 %39)
%41 = bitcast %union.anon* %10 to i8**
store i8* %40, i8** %41
%42 = bitcast %union.anon* %10 to [2 x i8]*
%43 = getelementptr inbounds [2 x i8], [2 x i8]* %42, i64 0, i64 0
%44 = load i8, i8* %43
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %5
store i8 %44, i8* %45
%47 = bitcast %union.anon* %10 to [2 x i8]*
%48 = getelementptr inbounds [2 x i8], [2 x i8]* %47, i64 0, i64 1
%49 = load i8, i8* %48
%50 = load i8*, i8** %5
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %5
store i8 %49, i8* %50
%52 = load i8*, i8** %5
%53 = load i8*, i8** %8
%54 = call i32 @strcpy(i8* %52, i8* %53)
%55 = load i8*, i8** %5
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
ret i8* %58
}

LLVM IR (-O2):
define i8* @add_option(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = trunc i32 %1 to i8
%6 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %5, i8* %0
%7 = tail call i32 @strlen(i8* %2)
%8 = tail call i8* @htons(i32 %7)
%9 = ptrtoint i8* %8 to i64
%10 = trunc i64 %9 to i8
%11 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %10, i8* %6
%12 = lshr i64 %9, 8
%13 = trunc i64 %12 to i8
%14 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %13, i8* %11
%15 = tail call i32 @strcpy(i8* %14, i8* %2)
%16 = sext i32 %7 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = tail call i32 @strlen(i8* %3)
%19 = tail call i8* @htons(i32 %18)
%20 = ptrtoint i8* %19 to i64
%21 = trunc i64 %20 to i8
%22 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %21, i8* %17
%23 = lshr i64 %20, 8
%24 = trunc i64 %23 to i8
%25 = getelementptr inbounds i8, i8* %22, i64 1
store i8 %24, i8* %22
%26 = tail call i32 @strcpy(i8* %25, i8* %3)
%27 = sext i32 %18 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
ret i8* %28
}