#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*/ perror(char *);
scalar_t__ send_data(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int send_tunnel_ok(int client_sock) {
  char *resp = "HTTP/1.1 200 Connection Established\r\n\r\n";
  int len = strlen(resp);
  char buffer[len + 1];
  strcpy(buffer, resp);
  if (send_data(client_sock, buffer, len) < 0) {
    perror("Send http tunnel response  failed\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<send_tunnel_ok>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%edx
call   1050 <send_data@plt>
cmp    $0x0,%rax
jge    11cc <send_tunnel_ok+0x8c>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11da <send_tunnel_ok+0x9a>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_tunnel_ok>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
lea    0xeab(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    0x1(%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1050 <send_data@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     11a6 <send_tunnel_ok+0x66>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7b(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
jmp    1199 <send_tunnel_ok+0x59>

LLVM IR (-O0):
@.str = [40 x i8] c"HTTP/1.1 200 Connection Established\0D\0A\0D\0A\00"
@.str.1 = [35 x i8] c"Send http tunnel response failed\0A\00"
define i32 @send_tunnel_ok(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %3
store i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i8*, i8** %4
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i32, i32* %3
%19 = load i32, i32* %5
%20 = call i64 @send_data(i32 %18, i8* %15, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %1
%23 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
store i32 1, i32* %8
br label %25
24: ; preds = %1
store i32 0, i32* %2
store i32 1, i32* %8
br label %25
25: ; preds = %24, %22
%26 = load i8*, i8** %6
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [40 x i8] c"HTTP/1.1 200 Connection Established\0D\0A\0D\0A\00"
@.str.1 = [35 x i8] c"Send http tunnel response failed\0A\00"
define i32 @send_tunnel_ok(i32 %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%7 = call i64 @send_data(i32 %0, i8* %5, i32 %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ -1, %9 ], [ 0, %1 ]
ret i32 %12
}