#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 int /*<<< orphan*/ escaped_param_value;

/* Variables and functions */
scalar_t__ guac_kubernetes_escape_url_component(char *, int, char const *);
int snprintf(char *, int, char *, char, char const *, char *);
int guac_kubernetes_append_endpoint_param(char *buffer, int length,
                                          const char *param_name,
                                          const char *param_value) {
  char escaped_param_value[1024];
  if (guac_kubernetes_escape_url_component(
          escaped_param_value, sizeof(escaped_param_value), param_value))
    return 1;
  char *str = buffer;
  int str_len = 0;
  int qmark = 0;
  while (*str != '\0') {
    if (*str == '?')
      qmark = 1;
    str_len++;
    if (str_len >= length)
      return 1;
    str++;
  }
  char delimiter = '?';
  if (qmark)
    delimiter = '&';
  buffer += str_len;
  length -= str_len;
  int written = snprintf(buffer, length, "%c%s=%s", delimiter, param_name,
                         escaped_param_value);
  return (written < 0 || written >= length);
}


x86 assembly (clang, -O0):
<guac_kubernetes_append_endpoint_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x400,%esi
call   1040 <guac_kubernetes_escape_url_component@plt>
cmp    $0x0,%rax
je     1165 <guac_kubernetes_append_endpoint_param+0x45>
movl   $0x1,-0x4(%rbp)
jmp    1294 <guac_kubernetes_append_endpoint_param+0x174>
mov    -0x10(%rbp),%rax
mov    %rax,-0x438(%rbp)
movl   $0x0,-0x43c(%rbp)
movl   $0x0,-0x440(%rbp)
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f5 <guac_kubernetes_append_endpoint_param+0xd5>
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3f,%eax
jne    11b4 <guac_kubernetes_append_endpoint_param+0x94>
movl   $0x1,-0x440(%rbp)
mov    -0x43c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x43c(%rbp)
mov    -0x43c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11de <guac_kubernetes_append_endpoint_param+0xbe>
movl   $0x1,-0x4(%rbp)
jmp    1294 <guac_kubernetes_append_endpoint_param+0x174>
mov    -0x438(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x438(%rbp)
jmp    1184 <guac_kubernetes_append_endpoint_param+0x64>
movb   $0x3f,-0x441(%rbp)
cmpl   $0x0,-0x440(%rbp)
je     1210 <guac_kubernetes_append_endpoint_param+0xf0>
movb   $0x26,-0x441(%rbp)
mov    -0x43c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x43c(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x441(%rbp),%al
mov    -0x20(%rbp),%r8
lea    -0x430(%rbp),%r9
lea    0xdaf(%rip),%rdx
movsbl %al,%ecx
call   1030 <snprintf@plt>
mov    %eax,-0x448(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x448(%rbp)
mov    %al,-0x449(%rbp)
jl     1286 <guac_kubernetes_append_endpoint_param+0x166>
mov    -0x448(%rbp),%eax
cmp    -0x14(%rbp),%eax
setge  %al
mov    %al,-0x449(%rbp)
mov    -0x449(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guac_kubernetes_append_endpoint_param>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rcx,%rdx
call   1040 <guac_kubernetes_escape_url_component@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11cb <guac_kubernetes_append_endpoint_param+0xab>
cmp    $0x2,%ebp
mov    $0x1,%ecx
cmovge %ebp,%ecx
xor    %eax,%eax
xor    %esi,%esi
jmp    117d <guac_kubernetes_append_endpoint_param+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%esi
add    $0x1,%rax
cmp    %eax,%ecx
je     11c6 <guac_kubernetes_append_endpoint_param+0xa6>
movzbl (%rbx,%rax,1),%edx
cmp    $0x3f,%dl
je     1170 <guac_kubernetes_append_endpoint_param+0x50>
test   %dl,%dl
jne    1175 <guac_kubernetes_append_endpoint_param+0x55>
add    %rax,%rbx
sub    %eax,%ebp
test   %esi,%esi
mov    $0x3f,%eax
mov    $0x26,%ecx
cmove  %eax,%ecx
lea    0xe5b(%rip),%rdx
mov    %rsp,%r9
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%r8
call   1030 <snprintf@plt>
test   %eax,%eax
sets   %cl
cmp    %ebp,%eax
setge  %al
or     %cl,%al
movzbl %al,%eax
jmp    11cb <guac_kubernetes_append_endpoint_param+0xab>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%c%s=%s\00"
define i32 @guac_kubernetes_append_endpoint_param(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%17 = load i8*, i8** %9
%18 = call i64 @guac_kubernetes_escape_url_component(i8* %16, i32 1024, i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 1, i32* %5
br label %71
21: ; preds = %4
%22 = load i8*, i8** %6
store i8* %22, i8** %11
store i32 0, i32* %12
store i32 0, i32* %13
br label %23
23: ; preds = %41, %21
%24 = load i8*, i8** %11
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %23
%29 = load i8*, i8** %11
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 63
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 1, i32* %13
br label %34
34: ; preds = %33, %28
%35 = load i32, i32* %12
%36 = add nsw i32 %35, 1
store i32 %36, i32* %12
%37 = load i32, i32* %12
%38 = load i32, i32* %7
%39 = icmp sge i32 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 1, i32* %5
br label %71
41: ; preds = %34
%42 = load i8*, i8** %11
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %11
br label %23
44: ; preds = %23
store i8 63, i8* %14
%45 = load i32, i32* %13
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44
store i8 38, i8* %14
br label %48
48: ; preds = %47, %44
%49 = load i32, i32* %12
%50 = load i8*, i8** %6
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %50, i64 %51
store i8* %52, i8** %6
%53 = load i32, i32* %12
%54 = load i32, i32* %7
%55 = sub nsw i32 %54, %53
store i32 %55, i32* %7
%56 = load i8*, i8** %6
%57 = load i32, i32* %7
%58 = load i8, i8* %14
%59 = load i8*, i8** %8
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%61 = call i32 @snprintf(i8* %56, i32 %57, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 signext %58, i8* %59, i8* %60)
store i32 %61, i32* %15
%62 = load i32, i32* %15
%63 = icmp slt i32 %62, 0
br i1 %63, label %68, label %64
64: ; preds = %48
%65 = load i32, i32* %15
%66 = load i32, i32* %7
%67 = icmp sge i32 %65, %66
br label %68
68: ; preds = %64, %48
%69 = phi i1 [ true, %48 ], [ %67, %64 ]
%70 = zext i1 %69 to i32
store i32 %70, i32* %5
br label %71
71: ; preds = %68, %40, %20
%72 = load i32, i32* %5
ret i32 %72
}

LLVM IR (-O2):
@.str = [8 x i8] c"%c%s=%s\00"
define i32 @guac_kubernetes_append_endpoint_param(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = call i64 @guac_kubernetes_escape_url_component(i8* %6, i32 1024, i8* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %33
9: ; preds = %4
%10 = call i32 @llvm.smax.i32(i32 %1, i32 1)
br label %11
11: ; preds = %9, %17
%12 = phi i8* [ %20, %17 ], [ %0, %9 ]
%13 = phi i32 [ %19, %17 ], [ 0, %9 ]
%14 = phi i32 [ %18, %17 ], [ 0, %9 ]
%15 = load i8, i8* %12
switch i8 %15, label %17 [
i8 0, label %22
i8 63, label %16
]
16: ; preds = %11
br label %17
17: ; preds = %11, %16
%18 = phi i32 [ 1, %16 ], [ %14, %11 ]
%19 = add nuw nsw i32 %13, 1
%20 = getelementptr inbounds i8, i8* %12, i64 1
%21 = icmp eq i32 %19, %10
br i1 %21, label %33, label %11
22: ; preds = %11
%23 = icmp eq i32 %14, 0
%24 = select i1 %23, i8 63, i8 38
%25 = zext i32 %13 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = sub nsw i32 %1, %13
%28 = call i32 @snprintf(i8* %26, i32 %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 signext %24, i8* %2, i8* %6)
%29 = icmp slt i32 %28, 0
%30 = icmp sge i32 %28, %27
%31 = or i1 %29, %30
%32 = zext i1 %31 to i32
br label %33
33: ; preds = %17, %22, %4
%34 = phi i32 [ 1, %4 ], [ %32, %22 ], [ 1, %17 ]
ret i32 %34
}