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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int establish_connection(char const *, char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int recv(int, char **, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void send_message(const char *hostname, const char *port, char message) {
  int sock_fd = establish_connection(hostname, port);
  if (sock_fd == -1) {
    fprintf(stderr, "Could not connect to ssh-tunneld running on %s:%s\n",
            hostname, port);
    exit(EXIT_FAILURE);
  }
  if (send(sock_fd, &message, sizeof(message), 0) != 1) {
    perror("send");
    exit(EXIT_FAILURE);
  }
  char buffer[1];
  if (recv(sock_fd, &buffer, sizeof(buffer), 0) != 1) {
    perror("recv");
    exit(EXIT_FAILURE);
  }
  if (buffer[0] != message) {
    fprintf(stderr, "Received incorrect response from ssh-tunneld. Exiting.\n");
    exit(EXIT_FAILURE);
  }
  close(sock_fd);
}


x86 assembly (clang, -O0):
<send_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <establish_connection@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11cc <send_message+0x5c>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x1,%eax
je     1202 <send_message+0x92>
lea    0xe44(%rip),%rdi
call   1080 <perror@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x1,%eax
je     1238 <send_message+0xc8>
lea    0xe13(%rip),%rdi
call   1080 <perror@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movsbl -0x19(%rbp),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     126d <send_message+0xfd>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_message>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %dl,0xe(%rsp)
call   1040 <establish_connection@plt>
cmp    $0xffffffff,%eax
je     11da <send_message+0x6a>
mov    %eax,%ebx
lea    0xe(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x1,%eax
jne    11f9 <send_message+0x89>
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x1,%eax
jne    1202 <send_message+0x92>
mov    0xf(%rsp),%al
cmp    0xe(%rsp),%al
jne    1210 <send_message+0xa0>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1227 <send_message+0xb7>
lea    0xe33(%rip),%rdi
jmp    1209 <send_message+0x99>
lea    0xe2f(%rip),%rdi
call   1080 <perror@plt>
jmp    1227 <send_message+0xb7>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"Could not connect to ssh-tunneld running on %s:%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"send\00"
@.str.2 = [5 x i8] c"recv\00"
@.str.3 = [56 x i8] c"Received incorrect response from ssh-tunneld. Exiting.\0A\00"
define void @send_message(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca [1 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 @establish_connection(i8* %9, i8* %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %3
%22 = load i32, i32* %7
%23 = call i32 @send(i32 %22, i8* %6, i32 1, i32 0)
%24 = icmp ne i32 %23, 1
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %21
%30 = load i32, i32* %7
%31 = bitcast [1 x i8]* %8 to i8**
%32 = call i32 @recv(i32 %30, i8** %31, i32 1, i32 0)
%33 = icmp ne i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %29
%39 = getelementptr inbounds [1 x i8], [1 x i8]* %8, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = load i8, i8* %6
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %41, %43
br i1 %44, label %45, label %50
45: ; preds = %38
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %38
%51 = load i32, i32* %7
%52 = call i32 @close(i32 %51)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"Could not connect to ssh-tunneld running on %s:%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"send\00"
@.str.2 = [5 x i8] c"recv\00"
@.str.3 = [56 x i8] c"Received incorrect response from ssh-tunneld. Exiting.\0A\00"
define void @send_message(i8* %0, i8* %1, i8 signext %2) {
%4 = alloca i8
%5 = alloca [1 x i8]
store i8 %2, i8* %4
%6 = tail call i32 @establish_connection(i8* %0, i8* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %3
%14 = call i32 @send(i32 %6, i8* %4, i32 1, i32 0)
%15 = icmp eq i32 %14, 1
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %13
%21 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%22 = bitcast [1 x i8]* %5 to i8**
%23 = call i32 @recv(i32 %6, i8** %22, i32 1, i32 0)
%24 = icmp eq i32 %23, 1
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %20
%30 = load i8, i8* %21
%31 = load i8, i8* %4
%32 = icmp eq i8 %30, %31
br i1 %32, label %38, label %33
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %29
%39 = call i32 @close(i32 %6)
ret void
}