#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 */
struct sockaddr_in {
  int dummy;
};
struct hostent {
  int dummy;
};

/* Variables and functions */
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ banner();
int /*<<< orphan*/ command_loop(int, char *, char *);
int connectto(char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int sock_fd, port;
  struct sockaddr_in serveraddr;
  struct hostent *server;
  char *hostname;
  if (argc != 3) {
    fprintf(stderr, "usage: %s <hostname> <port>\n", argv[0]);
    exit(0);
  }
  hostname = argv[1];
  port = atoi(argv[2]);
  char c_port[4];
  sprintf(c_port, "%d", port);
  banner();
  sock_fd = connectto(hostname, c_port);
  command_loop(sock_fd, hostname, c_port);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b3 <main+0x43>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
lea    -0x34(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe40(%rip),%rsi
call   1080 <sprintf@plt>
mov    $0x0,%al
call   1040 <banner@plt>
mov    -0x30(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   1030 <connectto@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1060 <command_loop@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11cc <main+0x5c>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
lea    0xe90(%rip),%rsi
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%edx
call   1080 <sprintf@plt>
xor    %eax,%eax
call   1040 <banner@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <connectto@plt>
mov    %eax,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <command_loop@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe21(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.hostent = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"usage: %s <hostname> <port>\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.hostent*
%10 = alloca i8*
%11 = alloca [4 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %10
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%30 = load i32, i32* %7
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = call i32 (...) @banner()
%33 = load i8*, i8** %10
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%35 = call i32 @connectto(i8* %33, i8* %34)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = load i8*, i8** %10
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %11, i64 0, i64 0
%39 = call i32 @command_loop(i32 %36, i8* %37, i8* %38)
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"usage: %s <hostname> <port>\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%17 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%18 = tail call i32 (...) @banner()
%19 = call i32 @connectto(i8* %12, i8* %16)
%20 = call i32 @command_loop(i32 %19, i8* %12, i8* %16)
%21 = load i32, i32* @EXIT_SUCCESS
ret i32 %21
}