#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void check_ssh(void) {
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock == -1) {
    printf("GOOD: SSH server not available on localhost.\n");
    return;
  }
  struct sockaddr_in server;
  server.sin_addr.s_addr = inet_addr("127.0.0.1");
  server.sin_family = AF_INET;
  server.sin_port = htons(22);
  if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0)
    printf("GOOD: SSH server not available on localhost.\n");
  else {
    printf("MAYBE: an SSH server is accessible on localhost. ");
    printf("It could be a good idea to create a new network namespace using "
           "\"--net=none\" or \"--net=eth0\".\n");
  }
  close(sock);
}


x86 assembly (clang, -O0):
<check_ssh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    119f <check_ssh+0x3f>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
jmp    1213 <check_ssh+0xb3>
lea    0xe88(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x16,%edi
call   1030 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1070 <connect@plt>
cmp    $0x0,%rax
jge    11f3 <check_ssh+0x93>
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
jmp    120b <check_ssh+0xab>
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_ssh>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e6a(%rip),%r14
mov    (%r14),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     11e8 <check_ssh+0x78>
mov    %eax,%ebx
lea    0xe61(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    $0x16,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1080 <connect@plt>
test   %rax,%rax
js     11fb <check_ssh+0x8b>
lea    0xe30(%rip),%rdi
call   1050 <printf@plt>
lea    0xe56(%rip),%rdi
jmp    1202 <check_ssh+0x92>
lea    0xeab(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [46 x i8] c"GOOD: SSH server not available on localhost.\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [50 x i8] c"MAYBE: an SSH server is accessible on localhost. \00"
@.str.3 = [95 x i8] c"It could be a good idea to create a new network namespace using \22--net=none\22 or \22--net=eth0\22.\0A\00"
define void @check_ssh() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = call i32 @socket(i32 %3, i32 %4, i32 0)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %30
10: ; preds = %0
%11 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
store i32 %14, i32* %15
%16 = call i32 @htons(i32 22)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* %1
%19 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%20 = call i64 @connect(i32 %18, %struct.sockaddr* %19, i32 12)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %10
%23 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %27
24: ; preds = %10
%25 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @printf(i8* getelementptr inbounds ([95 x i8], [95 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %24, %22
%28 = load i32, i32* %1
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %27, %8
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [50 x i8] c"MAYBE: an SSH server is accessible on localhost. \00"
@str = [94 x i8] c"It could be a good idea to create a new network namespace using \22--net=none\22 or \22--net=eth0\22.\00"
@str.5 = [45 x i8] c"GOOD: SSH server not available on localhost.\00"
define void @check_ssh() {
%1 = alloca %struct.sockaddr_in
%2 = load i32, i32* @AF_INET
%3 = load i32, i32* @SOCK_STREAM
%4 = tail call i32 @socket(i32 %2, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.5, i64 0, i64 0))
br label %25
8: ; preds = %0
%9 = bitcast %struct.sockaddr_in* %1 to i8*
%10 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 22)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %14, i32* %15
%16 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%17 = call i64 @connect(i32 %4, %struct.sockaddr* %16, i32 12)
%18 = icmp slt i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %8
%20 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %8, %19
%22 = phi i8* [ getelementptr inbounds ([94 x i8], [94 x i8]* @str, i64 0, i64 0), %19 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @str.5, i64 0, i64 0), %8 ]
%23 = call i32 @puts(i8* dereferenceable(1) %22)
%24 = call i32 @close(i32 %4)
br label %25
25: ; preds = %21, %6
ret void
}