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

/* Variables and functions */
scalar_t__ guac_kubernetes_escape_url_component(char *, int, char const *);
int snprintf(char *, int, char *, char *, char *, ...);
int guac_kubernetes_endpoint_attach(char *buffer, int length,
                                    const char *kubernetes_namespace,
                                    const char *kubernetes_pod,
                                    const char *kubernetes_container) {
  int written;
  char escaped_namespace[1024];
  char escaped_pod[1024];
  char escaped_container[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;
  if (kubernetes_container != NULL) {
    if (guac_kubernetes_escape_url_component(
            escaped_container, sizeof(escaped_container), kubernetes_container))
      return 1;
    written = snprintf(buffer, length,
                       "/api/v1/namespaces/%s/pods/%s/attach"
                       "?container=%s&stdin=true&stdout=true&tty=true",
                       escaped_namespace, escaped_pod, escaped_container);
  } else {
    written = snprintf(buffer, length,
                       "/api/v1/namespaces/%s/pods/%s/attach"
                       "?stdin=true&stdout=true&tty=true",
                       escaped_namespace, escaped_pod);
  }
  return !(written < length - 1);
}


x86 assembly (clang, -O0):
<guac_kubernetes_endpoint_attach>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1040 <guac_kubernetes_escape_url_component@plt>
cmp    $0x0,%rax
je     1169 <guac_kubernetes_endpoint_attach+0x49>
movl   $0x1,-0x4(%rbp)
jmp    123a <guac_kubernetes_endpoint_attach+0x11a>
lea    -0x840(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x400,%esi
call   1040 <guac_kubernetes_escape_url_component@plt>
cmp    $0x0,%rax
je     1194 <guac_kubernetes_endpoint_attach+0x74>
movl   $0x1,-0x4(%rbp)
jmp    123a <guac_kubernetes_endpoint_attach+0x11a>
cmpq   $0x0,-0x30(%rbp)
je     11fc <guac_kubernetes_endpoint_attach+0xdc>
lea    -0xc40(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x400,%esi
call   1040 <guac_kubernetes_escape_url_component@plt>
cmp    $0x0,%rax
je     11ca <guac_kubernetes_endpoint_attach+0xaa>
movl   $0x1,-0x4(%rbp)
jmp    123a <guac_kubernetes_endpoint_attach+0x11a>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x440(%rbp),%rcx
lea    -0x840(%rbp),%r8
lea    -0xc40(%rbp),%r9
lea    0xe13(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
jmp    1222 <guac_kubernetes_endpoint_attach+0x102>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x440(%rbp),%rcx
lea    -0x840(%rbp),%r8
lea    0xe3a(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
setl   %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guac_kubernetes_endpoint_attach>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc00,%rsp
mov    %r8,%r12
mov    %rcx,%rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x400(%rsp),%rdi
mov    $0x400,%esi
call   1040 <guac_kubernetes_escape_url_component@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11e4 <guac_kubernetes_endpoint_attach+0xc4>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1040 <guac_kubernetes_escape_url_component@plt>
test   %rax,%rax
jne    11e4 <guac_kubernetes_endpoint_attach+0xc4>
test   %r12,%r12
je     11b8 <guac_kubernetes_endpoint_attach+0x98>
lea    0x800(%rsp),%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1040 <guac_kubernetes_escape_url_component@plt>
test   %rax,%rax
jne    11e4 <guac_kubernetes_endpoint_attach+0xc4>
lea    0xe6a(%rip),%rdx
lea    0x400(%rsp),%rcx
mov    %rsp,%r8
lea    0x800(%rsp),%r9
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11d7 <guac_kubernetes_endpoint_attach+0xb7>
lea    0xe93(%rip),%rdx
lea    0x400(%rsp),%rcx
mov    %rsp,%r8
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
add    $0xffffffff,%r14d
xor    %ebp,%ebp
cmp    %r14d,%eax
setge  %bpl
mov    %ebp,%eax
add    $0xc00,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [82 x i8] c"/api/v1/namespaces/%s/pods/%s/attach?container=%s&stdin=true&stdout=true&tty=true\00"
@.str.1 = [69 x i8] c"/api/v1/namespaces/%s/pods/%s/attach?stdin=true&stdout=true&tty=true\00"
define i32 @guac_kubernetes_endpoint_attach(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca [1024 x i8]
%14 = alloca [1024 x i8]
%15 = alloca [1024 x i8]
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, 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 = %5
store i32 1, i32* %6
br label %56
21: ; preds = %5
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%23 = load i8*, i8** %10
%24 = call i64 @guac_kubernetes_escape_url_component(i8* %22, i32 1024, i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 1, i32* %6
br label %56
27: ; preds = %21
%28 = load i8*, i8** %11
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %43
30: ; preds = %27
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%32 = load i8*, i8** %11
%33 = call i64 @guac_kubernetes_escape_url_component(i8* %31, i32 1024, i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 1, i32* %6
br label %56
36: ; preds = %30
%37 = load i8*, i8** %7
%38 = load i32, i32* %8
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%42 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %37, i32 %38, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0), i8* %39, i8* %40, i8* %41)
store i32 %42, i32* %12
br label %49
43: ; preds = %27
%44 = load i8*, i8** %7
%45 = load i32, i32* %8
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%48 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %44, i32 %45, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* %47)
store i32 %48, i32* %12
br label %49
49: ; preds = %43, %36
%50 = load i32, i32* %12
%51 = load i32, i32* %8
%52 = sub nsw i32 %51, 1
%53 = icmp slt i32 %50, %52
%54 = xor i1 %53, true
%55 = zext i1 %54 to i32
store i32 %55, i32* %6
br label %56
56: ; preds = %49, %35, %26, %20
%57 = load i32, i32* %6
ret i32 %57
}

LLVM IR (-O2):
@.str = [82 x i8] c"/api/v1/namespaces/%s/pods/%s/attach?container=%s&stdin=true&stdout=true&tty=true\00"
@.str.1 = [69 x i8] c"/api/v1/namespaces/%s/pods/%s/attach?stdin=true&stdout=true&tty=true\00"
define i32 @guac_kubernetes_endpoint_attach(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%12 = call i64 @guac_kubernetes_escape_url_component(i8* %9, i32 1024, i8* %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %5
%15 = call i64 @guac_kubernetes_escape_url_component(i8* %10, i32 1024, i8* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = icmp eq i8* %4, null
br i1 %18, label %24, label %19
19: ; preds = %17
%20 = call i64 @guac_kubernetes_escape_url_component(i8* %11, i32 1024, i8* %4)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10, i8* %11)
br label %26
24: ; preds = %17
%25 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %10)
br label %26
26: ; preds = %24, %22
%27 = phi i32 [ %23, %22 ], [ %25, %24 ]
%28 = add nsw i32 %1, -1
%29 = icmp sge i32 %27, %28
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %19, %14, %5, %26
%32 = phi i32 [ %30, %26 ], [ 1, %5 ], [ 1, %14 ], [ 1, %19 ]
ret i32 %32
}