#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;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
void scanner(int port, char host[]) {
  int sock, n;
  struct hostent *server;
  struct sockaddr_in serv_addr;
  char buffer[4096];
  server = gethostbyname(host);
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    fprintf(stderr, "[-]Error creating socket");
    return;
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
        server->h_length);
  serv_addr.sin_port = htons(port);
  n = connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  sleep(2);
  if (n < 0) {
    fprintf(stderr, "[-]Error Connecting to port\n");
    return;
  }
  memset(buffer, 0, sizeof(buffer));
  strcpy(buffer, "garbage\r\n");
  n = write(sock, buffer, strlen(buffer));
  if (n < 0) {
    fprintf(stderr, "[-]Error writing (Port closed maybe?!)\n");
    return;
  }
  bzero(buffer, 4096);
  n = read(sock, buffer, 4096);
  if (n < 0) {
    fprintf(stderr, "[-]Error reading (Port closed maybe?!)\n");
    return;
  }
  fprintf(stdout, "[*]%s\n", buffer);
  close(sock);
}


x86 assembly (clang, -O0):
<scanner>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1241 <scanner+0x61>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    13bf <scanner+0x1df>
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
add    $0x4,%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bcopy@plt>
mov    -0x4(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
mov    %eax,-0x18(%rbp)
mov    $0x2,%edi
call   10f0 <sleep@plt>
cmpl   $0x0,-0x18(%rbp)
jge    12c5 <scanner+0xe5>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    13bf <scanner+0x1df>
lea    -0x1030(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
lea    -0x1030(%rbp),%rdi
lea    0xd50(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x103c(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x1038(%rbp)
lea    -0x1030(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x103c(%rbp),%edi
mov    -0x1038(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    134b <scanner+0x16b>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    13bf <scanner+0x1df>
lea    -0x1030(%rbp),%rdi
mov    $0x1000,%esi
call   10d0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x1030(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1399 <scanner+0x1b9>
mov    0x2c54(%rip),%rax
mov    (%rax),%edi
lea    0xcdb(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    13bf <scanner+0x1df>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
lea    -0x1030(%rbp),%rdx
lea    0xce0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scanner>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1010,%rsp
mov    %edi,%r14d
mov    %rsi,%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,%rbp
mov    0x2de4(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     1303 <scanner+0x123>
mov    %eax,%r12d
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbp),%rsi
lea    0x4(%rsp),%rdi
mov    0x0(%rbp),%edx
call   10c0 <memmove@plt>
mov    %r14d,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   10f0 <sleep@plt>
test   %ebp,%ebp
js     1329 <scanner+0x149>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1070 <memset@plt>
lea    0xda4(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
js     133b <scanner+0x15b>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1000,%esi
call   10d0 <bzero@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1090 <read@plt>
test   %eax,%eax
js     134d <scanner+0x16d>
mov    0x2ce4(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r12d,%edi
call   1080 <close@plt>
jmp    1364 <scanner+0x184>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
xor    %eax,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <fprintf@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    0xce0(%rip),%rsi
jmp    135d <scanner+0x17d>
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
lea    0xcf5(%rip),%rsi
jmp    135d <scanner+0x17d>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
lea    0xd0b(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
add    $0x1010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i32, i64 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"[-]Error creating socket\00"
@.str.1 = [29 x i8] c"[-]Error Connecting to port\0A\00"
@.str.2 = [10 x i8] c"garbage\0D\0A\00"
@.str.3 = [40 x i8] c"[-]Error writing (Port closed maybe?!)\0A\00"
@.str.4 = [40 x i8] c"[-]Error reading (Port closed maybe?!)\0A\00"
@stdout = global i32 0
@.str.5 = [7 x i8] c"[*]%s\0A\00"
define void @scanner(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca [4096 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call %struct.hostent* @gethostbyname(i8* %10)
store %struct.hostent* %11, %struct.hostent** %7
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %80
20: ; preds = %2
%21 = bitcast %struct.sockaddr_in* %8 to i8*
%22 = call i32 @bzero(i8* %21, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %23, i32* %24
%25 = load %struct.hostent*, %struct.hostent** %7
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = inttoptr i64 %27 to i8*
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
%31 = bitcast i32* %30 to i8*
%32 = load %struct.hostent*, %struct.hostent** %7
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @bcopy(i8* %28, i8* %31, i32 %34)
%36 = load i32, i32* %3
%37 = call i32 @htons(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %37, i32* %38
%39 = load i32, i32* %5
%40 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%41 = call i32 @connect(i32 %39, %struct.sockaddr* %40, i32 12)
store i32 %41, i32* %6
%42 = call i32 @sleep(i32 2)
%43 = load i32, i32* %6
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %20
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %80
48: ; preds = %20
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%50 = call i32 @memset(i8* %49, i32 0, i32 4096)
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%52 = call i32 @strcpy(i8* %51, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%53 = load i32, i32* %5
%54 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @write(i32 %53, i8* %54, i32 %56)
store i32 %57, i32* %6
%58 = load i32, i32* %6
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %48
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %80
63: ; preds = %48
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%65 = call i32 @bzero(i8* %64, i32 4096)
%66 = load i32, i32* %5
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%68 = call i32 @read(i32 %66, i8* %67, i32 4096)
store i32 %68, i32* %6
%69 = load i32, i32* %6
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %63
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %80
74: ; preds = %63
%75 = load i32, i32* @stdout
%76 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %76)
%78 = load i32, i32* %5
%79 = call i32 @close(i32 %78)
br label %80
80: ; preds = %74, %71, %60, %45, %17
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"[-]Error creating socket\00"
@.str.1 = [29 x i8] c"[-]Error Connecting to port\0A\00"
@.str.2 = [10 x i8] c"garbage\0D\0A\00"
@.str.3 = [40 x i8] c"[-]Error writing (Port closed maybe?!)\0A\00"
@.str.4 = [40 x i8] c"[-]Error reading (Port closed maybe?!)\0A\00"
@stdout = global i32 0
@.str.5 = [7 x i8] c"[*]%s\0A\00"
define void @scanner(i32 %0, i8* %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [4096 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = tail call %struct.hostent* @gethostbyname(i8* %1)
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %55
15: ; preds = %2
%16 = call i32 @bzero(i8* %5, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 1
%20 = load i64, i64* %19
%21 = inttoptr i64 %20 to i8*
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%23 = bitcast i32* %22 to i8*
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%25 = load i32, i32* %24
%26 = tail call i32 @htons(i32 %0)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %26, i32* %27
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i32 @connect(i32 %10, %struct.sockaddr* %28, i32 12)
%30 = call i32 @sleep(i32 2)
%31 = icmp slt i32 %29, 0
br i1 %31, label %32, label %35
32: ; preds = %15
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %55
35: ; preds = %15
%36 = call i32 @memset(i8* %6, i32 0, i32 4096)
%37 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @strlen(i8* %6)
%39 = call i32 @write(i32 %10, i8* %6, i32 %38)
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0))
br label %55
44: ; preds = %35
%45 = call i32 @bzero(i8* %6, i32 4096)
%46 = call i32 @read(i32 %10, i8* %6, i32 4096)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %55
51: ; preds = %44
%52 = load i32, i32* @stdout
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%54 = call i32 @close(i32 %10)
br label %55
55: ; preds = %51, %48, %41, %32, %12
ret void
}