#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_pod;
typedef int /*<<< orphan*/ escaped_namespace;

/* Variables and functions */
scalar_t__ guac_kubernetes_append_endpoint_param(char *, int, char *,
                                                 char const *);
scalar_t__ guac_kubernetes_escape_url_component(char *, int, char const *);
int snprintf(char *, int, char *, char *, char *, char *);
int guac_kubernetes_endpoint_uri(char *buffer, int length,
                                 const char *kubernetes_namespace,
                                 const char *kubernetes_pod,
                                 const char *kubernetes_container,
                                 const char *exec_command) {
  char escaped_namespace[1024];
  char escaped_pod[1024];
  if (guac_kubernetes_escape_url_component(
          escaped_namespace, sizeof(escaped_namespace), kubernetes_namespace))
    return 1;
  if (guac_kubernetes_escape_url_component(escaped_pod, sizeof(escaped_pod),
                                           kubernetes_pod))
    return 1;
  char *call = "attach";
  if (exec_command != NULL)
    call = "exec";
  int written;
  written = snprintf(buffer, length, "/api/v1/namespaces/%s/pods/%s/%s",
                     escaped_namespace, escaped_pod, call);
  if (written < 0 || written >= length)
    return 1;
  if (exec_command != NULL) {
    if (guac_kubernetes_append_endpoint_param(buffer, length, "command",
                                              exec_command))
      return 1;
  }
  if (kubernetes_container != NULL) {
    if (guac_kubernetes_append_endpoint_param(buffer, length, "container",
                                              kubernetes_container))
      return 1;
  }
  return (guac_kubernetes_append_endpoint_param(buffer, length, "stdin",
                                                "true")) ||
         (guac_kubernetes_append_endpoint_param(buffer, length, "stdout",
                                                "true")) ||
         (guac_kubernetes_append_endpoint_param(buffer, length, "tty", "true"));
}


x86 assembly (clang, -O0):
<guac_kubernetes_endpoint_uri>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <guac_kubernetes_escape_url_component@plt>
cmp    $0x0,%rax
je     117d <guac_kubernetes_endpoint_uri+0x4d>
movl   $0x1,-0x4(%rbp)
jmp    1332 <guac_kubernetes_endpoint_uri+0x202>
lea    -0x840(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x400,%esi
call   1050 <guac_kubernetes_escape_url_component@plt>
cmp    $0x0,%rax
je     11a8 <guac_kubernetes_endpoint_uri+0x78>
movl   $0x1,-0x4(%rbp)
jmp    1332 <guac_kubernetes_endpoint_uri+0x202>
lea    0xe51(%rip),%rax
mov    %rax,-0x848(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11cf <guac_kubernetes_endpoint_uri+0x9f>
lea    0xe3f(%rip),%rax
mov    %rax,-0x848(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x440(%rbp),%rcx
lea    -0x840(%rbp),%r8
mov    -0x848(%rbp),%r9
lea    0xe1a(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x84c(%rbp)
cmpl   $0x0,-0x84c(%rbp)
jl     1219 <guac_kubernetes_endpoint_uri+0xe9>
mov    -0x84c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1225 <guac_kubernetes_endpoint_uri+0xf5>
movl   $0x1,-0x4(%rbp)
jmp    1332 <guac_kubernetes_endpoint_uri+0x202>
cmpq   $0x0,-0x38(%rbp)
je     1262 <guac_kubernetes_endpoint_uri+0x132>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x38(%rbp),%rcx
lea    0xdeb(%rip),%rdx
call   1030 <guac_kubernetes_append_endpoint_param@plt>
cmp    $0x0,%rax
je     125d <guac_kubernetes_endpoint_uri+0x12d>
movl   $0x1,-0x4(%rbp)
jmp    1332 <guac_kubernetes_endpoint_uri+0x202>
jmp    1262 <guac_kubernetes_endpoint_uri+0x132>
cmpq   $0x0,-0x30(%rbp)
je     129f <guac_kubernetes_endpoint_uri+0x16f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rcx
lea    0xdb6(%rip),%rdx
call   1030 <guac_kubernetes_append_endpoint_param@plt>
cmp    $0x0,%rax
je     129a <guac_kubernetes_endpoint_uri+0x16a>
movl   $0x1,-0x4(%rbp)
jmp    1332 <guac_kubernetes_endpoint_uri+0x202>
jmp    129f <guac_kubernetes_endpoint_uri+0x16f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xd92(%rip),%rdx
lea    0xd91(%rip),%rcx
call   1030 <guac_kubernetes_append_endpoint_param@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x84d(%rbp)
jne    1324 <guac_kubernetes_endpoint_uri+0x1f4>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xd6e(%rip),%rdx
lea    0xd62(%rip),%rcx
call   1030 <guac_kubernetes_append_endpoint_param@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x84d(%rbp)
jne    1324 <guac_kubernetes_endpoint_uri+0x1f4>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xd46(%rip),%rdx
lea    0xd33(%rip),%rcx
call   1030 <guac_kubernetes_append_endpoint_param@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x84d(%rbp)
mov    -0x84d(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guac_kubernetes_endpoint_uri>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %r9,%rbp
mov    %r8,%r12
mov    %rcx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x400(%rsp),%rdi
mov    $0x400,%esi
call   1050 <guac_kubernetes_escape_url_component@plt>
mov    $0x1,%r13d
test   %rax,%rax
jne    1182 <guac_kubernetes_endpoint_uri+0x52>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <guac_kubernetes_escape_url_component@plt>
test   %rax,%rax
je     1197 <guac_kubernetes_endpoint_uri+0x67>
mov    %r13d,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %rbp,%rbp
lea    0xe5f(%rip),%rax
lea    0xe5f(%rip),%r9
cmove  %rax,%r9
lea    0xe59(%rip),%rdx
lea    0x400(%rsp),%rcx
mov    %rsp,%r8
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <snprintf@plt>
test   %eax,%eax
js     1182 <guac_kubernetes_endpoint_uri+0x52>
cmp    %r15d,%eax
jge    1182 <guac_kubernetes_endpoint_uri+0x52>
test   %rbp,%rbp
je     11f1 <guac_kubernetes_endpoint_uri+0xc1>
lea    0xe4f(%rip),%rdx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbp,%rcx
call   1030 <guac_kubernetes_append_endpoint_param@plt>
test   %rax,%rax
jne    1182 <guac_kubernetes_endpoint_uri+0x52>
test   %r12,%r12
je     1214 <guac_kubernetes_endpoint_uri+0xe4>
lea    0xe38(%rip),%rdx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12,%rcx
call   1030 <guac_kubernetes_append_endpoint_param@plt>
test   %rax,%rax
jne    1182 <guac_kubernetes_endpoint_uri+0x52>
lea    0xe24(%rip),%rdx
lea    0xe23(%rip),%rcx
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <guac_kubernetes_append_endpoint_param@plt>
test   %rax,%rax
jne    1182 <guac_kubernetes_endpoint_uri+0x52>
lea    0xe0d(%rip),%rdx
lea    0xe01(%rip),%rcx
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <guac_kubernetes_append_endpoint_param@plt>
test   %rax,%rax
jne    1182 <guac_kubernetes_endpoint_uri+0x52>
lea    0xdf2(%rip),%rdx
lea    0xddf(%rip),%rcx
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <guac_kubernetes_append_endpoint_param@plt>
xor    %r13d,%r13d
test   %rax,%rax
setne  %r13b
jmp    1182 <guac_kubernetes_endpoint_uri+0x52>

LLVM IR (-O0):
@.str = [7 x i8] c"attach\00"
@.str.1 = [5 x i8] c"exec\00"
@.str.2 = [33 x i8] c"/api/v1/namespaces/%s/pods/%s/%s\00"
@.str.3 = [8 x i8] c"command\00"
@.str.4 = [10 x i8] c"container\00"
@.str.5 = [6 x i8] c"stdin\00"
@.str.6 = [5 x i8] c"true\00"
@.str.7 = [7 x i8] c"stdout\00"
@.str.8 = [4 x i8] c"tty\00"
define i32 @guac_kubernetes_endpoint_uri(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca [1024 x i8]
%15 = alloca [1024 x i8]
%16 = alloca i8*
%17 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%19 = load i8*, i8** %10
%20 = call i64 @guac_kubernetes_escape_url_component(i8* %18, i32 1024, i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %6
store i32 1, i32* %7
br label %87
23: ; preds = %6
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%25 = load i8*, i8** %11
%26 = call i64 @guac_kubernetes_escape_url_component(i8* %24, i32 1024, i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 1, i32* %7
br label %87
29: ; preds = %23
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %16
%30 = load i8*, i8** %13
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %33
32: ; preds = %29
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %16
br label %33
33: ; preds = %32, %29
%34 = load i8*, i8** %8
%35 = load i32, i32* %9
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%38 = load i8*, i8** %16
%39 = call i32 @snprintf(i8* %34, i32 %35, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %36, i8* %37, i8* %38)
store i32 %39, i32* %17
%40 = load i32, i32* %17
%41 = icmp slt i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %33
%43 = load i32, i32* %17
%44 = load i32, i32* %9
%45 = icmp sge i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42, %33
store i32 1, i32* %7
br label %87
47: ; preds = %42
%48 = load i8*, i8** %13
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %58
50: ; preds = %47
%51 = load i8*, i8** %8
%52 = load i32, i32* %9
%53 = load i8*, i8** %13
%54 = call i64 @guac_kubernetes_append_endpoint_param(i8* %51, i32 %52, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %50
store i32 1, i32* %7
br label %87
57: ; preds = %50
br label %58
58: ; preds = %57, %47
%59 = load i8*, i8** %12
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %69
61: ; preds = %58
%62 = load i8*, i8** %8
%63 = load i32, i32* %9
%64 = load i8*, i8** %12
%65 = call i64 @guac_kubernetes_append_endpoint_param(i8* %62, i32 %63, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %61
store i32 1, i32* %7
br label %87
68: ; preds = %61
br label %69
69: ; preds = %68, %58
%70 = load i8*, i8** %8
%71 = load i32, i32* %9
%72 = call i64 @guac_kubernetes_append_endpoint_param(i8* %70, i32 %71, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%73 = icmp ne i64 %72, 0
br i1 %73, label %84, label %74
74: ; preds = %69
%75 = load i8*, i8** %8
%76 = load i32, i32* %9
%77 = call i64 @guac_kubernetes_append_endpoint_param(i8* %75, i32 %76, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%78 = icmp ne i64 %77, 0
br i1 %78, label %84, label %79
79: ; preds = %74
%80 = load i8*, i8** %8
%81 = load i32, i32* %9
%82 = call i64 @guac_kubernetes_append_endpoint_param(i8* %80, i32 %81, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%83 = icmp ne i64 %82, 0
br label %84
84: ; preds = %79, %74, %69
%85 = phi i1 [ true, %74 ], [ true, %69 ], [ %83, %79 ]
%86 = zext i1 %85 to i32
store i32 %86, i32* %7
br label %87
87: ; preds = %84, %67, %56, %46, %28, %22
%88 = load i32, i32* %7
ret i32 %88
}

LLVM IR (-O2):
@.str = [7 x i8] c"attach\00"
@.str.1 = [5 x i8] c"exec\00"
@.str.2 = [33 x i8] c"/api/v1/namespaces/%s/pods/%s/%s\00"
@.str.3 = [8 x i8] c"command\00"
@.str.4 = [10 x i8] c"container\00"
@.str.5 = [6 x i8] c"stdin\00"
@.str.6 = [5 x i8] c"true\00"
@.str.7 = [7 x i8] c"stdout\00"
@.str.8 = [4 x i8] c"tty\00"
define i32 @guac_kubernetes_endpoint_uri(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%11 = call i64 @guac_kubernetes_escape_url_component(i8* %9, i32 1024, i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %42
13: ; preds = %6
%14 = call i64 @guac_kubernetes_escape_url_component(i8* %10, i32 1024, i8* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %42
16: ; preds = %13
%17 = icmp eq i8* %5, null
%18 = select i1 %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%19 = call i32 @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %10, i8* %18)
%20 = icmp sgt i32 %19, -1
%21 = icmp slt i32 %19, %1
%22 = and i1 %20, %21
br i1 %22, label %23, label %42
23: ; preds = %16
br i1 %17, label %27, label %24
24: ; preds = %23
%25 = call i64 @guac_kubernetes_append_endpoint_param(i8* %0, i32 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %24, %23
%28 = icmp eq i8* %4, null
br i1 %28, label %32, label %29
29: ; preds = %27
%30 = call i64 @guac_kubernetes_append_endpoint_param(i8* %0, i32 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %29, %27
%33 = call i64 @guac_kubernetes_append_endpoint_param(i8* %0, i32 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = call i64 @guac_kubernetes_append_endpoint_param(i8* %0, i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = call i64 @guac_kubernetes_append_endpoint_param(i8* %0, i32 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%40 = icmp ne i64 %39, 0
%41 = zext i1 %40 to i32
br label %42
42: ; preds = %16, %24, %29, %38, %35, %32, %13, %6
%43 = phi i32 [ 1, %6 ], [ 1, %13 ], [ 1, %16 ], [ 1, %24 ], [ 1, %29 ], [ 1, %35 ], [ 1, %32 ], [ %41, %38 ]
ret i32 %43
}