#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 in_addr {
  int /*<<< orphan*/ s_addr;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
scalar_t__ inet_aton(char *, struct in_addr *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
int tconnect(struct in_addr *, int, int);
int /*<<< orphan*/ write(int, char const *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int ii;
  char *server;
  int port;
  int nconns, ccreat = 0;
  struct hostent *he;
  struct in_addr inadr;
  struct sockaddr_in sin;
  if (argc < 4) {
    printf("use: %s server port numconns\n", argv[0]);
    return (1);
  }
  server = argv[1];
  port = atoi(argv[2]);
  nconns = atoi(argv[3]);
  if (inet_aton(server, &inadr) == 0) {
    if ((he = gethostbyname(server)) == NULL) {
      fprintf(stderr, "unable to resolve: %s\n", server);
      return (-1);
    }
    memcpy(&inadr.s_addr, he->h_addr_list[0], he->h_length);
  }
  for (ii = 0; ii < nconns; ii++) {
    int sfd = tconnect(&inadr, port, 30);
    if (sfd != -1) {
      char const *req = "GET / HTTP/1.0\r\n";
      write(sfd, req, strlen(req));
      ++ccreat;
    }
  }
  printf("%d connections created ...\n", ccreat);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11d8 <main+0x48>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1305 <main+0x175>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <inet_aton@plt>
cmp    $0x0,%rax
jne    1270 <main+0xe0>
mov    -0x20(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1257 <main+0xc7>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdd8(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <main+0x175>
lea    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
call   1080 <memcpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12ed <main+0x15d>
mov    -0x24(%rbp),%esi
lea    -0x40(%rbp),%rdi
mov    $0x1e,%edx
call   10a0 <tconnect@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
je     12da <main+0x14a>
lea    0xd8d(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12df <main+0x14f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1277 <main+0xe7>
mov    -0x2c(%rbp),%esi
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
jg     11bf <main+0x2f>
mov    0x0(%rbp),%rsi
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    1279 <main+0xe9>
mov    0x8(%rbp),%rbx
mov    0x10(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r15d
mov    0x18(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1090 <inet_aton@plt>
test   %rax,%rax
jne    120b <main+0x7b>
mov    %rbx,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1288 <main+0xf8>
mov    0x8(%rax),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
mov    %rsp,%rdi
call   1080 <memcpy@plt>
mov    $0x0,%ebx
test   %ebp,%ebp
jle    1267 <main+0xd7>
xor    %ebx,%ebx
mov    %rsp,%r12
lea    0xe15(%rip),%r13
jmp    1235 <main+0xa5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%ebp
je     1267 <main+0xd7>
mov    %r12,%rdi
mov    %r15d,%esi
mov    $0x1e,%edx
call   10a0 <tconnect@plt>
cmp    $0xffffffff,%eax
je     1230 <main+0xa0>
mov    %eax,%r14d
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x1,%ebx
jmp    1230 <main+0xa0>
lea    0xdd8(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1279 <main+0xe9>

LLVM IR (-O0):
%struct.hostent = type { i32, i32* }
%struct.in_addr = type { i32 }
%struct.sockaddr_in = type { i32 }
@.str = [30 x i8] c"use: %s server port numconns\0A\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"unable to resolve: %s\0A\00"
@.str.2 = [17 x i8] c"GET / HTTP/1.0\0D\0A\00"
@.str.3 = [28 x i8] c"%d connections created ...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.hostent*
%12 = alloca %struct.in_addr
%13 = alloca %struct.sockaddr_in
%14 = alloca i32
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 4
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 1, i32* %3
br label %82
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %7
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %8
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %9
%35 = load i8*, i8** %7
%36 = call i64 @inet_aton(i8* %35, %struct.in_addr* %12)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %57
38: ; preds = %23
%39 = load i8*, i8** %7
%40 = call %struct.hostent* @gethostbyname(i8* %39)
store %struct.hostent* %40, %struct.hostent** %11
%41 = icmp eq %struct.hostent* %40, null
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %7
%45 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %44)
store i32 -1, i32* %3
br label %82
46: ; preds = %38
%47 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %12, i32 0, i32 0
%48 = load %struct.hostent*, %struct.hostent** %11
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %48, i32 0, i32 1
%50 = load i32*, i32** %49
%51 = getelementptr inbounds i32, i32* %50, i64 0
%52 = load i32, i32* %51
%53 = load %struct.hostent*, %struct.hostent** %11
%54 = getelementptr inbounds %struct.hostent, %struct.hostent* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @memcpy(i32* %47, i32 %52, i32 %55)
br label %57
57: ; preds = %46, %23
store i32 0, i32* %6
br label %58
58: ; preds = %76, %57
%59 = load i32, i32* %6
%60 = load i32, i32* %9
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %79
62: ; preds = %58
%63 = load i32, i32* %8
%64 = call i32 @tconnect(%struct.in_addr* %12, i32 %63, i32 30)
store i32 %64, i32* %14
%65 = load i32, i32* %14
%66 = icmp ne i32 %65, -1
br i1 %66, label %67, label %75
67: ; preds = %62
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %15
%68 = load i32, i32* %14
%69 = load i8*, i8** %15
%70 = load i8*, i8** %15
%71 = call i32 @strlen(i8* %70)
%72 = call i32 @write(i32 %68, i8* %69, i32 %71)
%73 = load i32, i32* %10
%74 = add nsw i32 %73, 1
store i32 %74, i32* %10
br label %75
75: ; preds = %67, %62
br label %76
76: ; preds = %75
%77 = load i32, i32* %6
%78 = add nsw i32 %77, 1
store i32 %78, i32* %6
br label %58
79: ; preds = %58
%80 = load i32, i32* %10
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %80)
store i32 0, i32* %3
br label %82
82: ; preds = %79, %42, %18
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32* }
@.str = [30 x i8] c"use: %s server port numconns\0A\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"unable to resolve: %s\0A\00"
@.str.2 = [17 x i8] c"GET / HTTP/1.0\0D\0A\00"
@.str.3 = [28 x i8] c"%d connections created ...\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.in_addr
%4 = bitcast %struct.in_addr* %3 to i8*
%5 = icmp slt i32 %0, 4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %52
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32 @atoi(i8* %16)
%18 = call i64 @inet_aton(i8* %11, %struct.in_addr* %3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %9
%21 = call %struct.hostent* @gethostbyname(i8* %11)
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %52
26: ; preds = %20
%27 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i64 0, i32 0
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 1
%29 = load i32*, i32** %28
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @memcpy(i32* %27, i32 %30, i32 %32)
br label %34
34: ; preds = %26, %9
%35 = icmp sgt i32 %17, 0
br i1 %35, label %36, label %49
36: ; preds = %34, %45
%37 = phi i32 [ %47, %45 ], [ 0, %34 ]
%38 = phi i32 [ %46, %45 ], [ 0, %34 ]
%39 = call i32 @tconnect(%struct.in_addr* %3, i32 %14, i32 30)
%40 = icmp eq i32 %39, -1
br i1 %40, label %45, label %41
41: ; preds = %36
%42 = call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @write(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = add nsw i32 %38, 1
br label %45
45: ; preds = %41, %36
%46 = phi i32 [ %44, %41 ], [ %38, %36 ]
%47 = add nuw nsw i32 %37, 1
%48 = icmp eq i32 %47, %17
br i1 %48, label %49, label %36
49: ; preds = %45, %34
%50 = phi i32 [ 0, %34 ], [ %46, %45 ]
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49, %23, %6
%53 = phi i32 [ 1, %6 ], [ -1, %23 ], [ 0, %49 ]
ret i32 %53
}