#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 ssize_t;
typedef int /*<<< orphan*/ request;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
scalar_t__ ECHILD;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int readn(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int tcp_connect(char *, char *);
scalar_t__ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i, j, fd, nchildren, nloops, nbytes;
  pid_t pid;
  ssize_t n;
  char request[1024], reply[16384];
  if (argc != 6) {
    fprintf(stderr, "Usage: %s <ip> <port> <children> <loops> <request>\n",
            argv[0]);
    exit(-1);
  }
  nchildren = atoi(argv[3]);
  nloops = atoi(argv[4]);
  nbytes = atoi(argv[5]);
  snprintf(request, sizeof(request), "%d\n", nbytes);
  for (i = 0; i < nchildren; ++i) {
    if ((pid = fork()) == 0) {
      for (j = 0; j < nloops; ++j) {
        fd = tcp_connect(argv[1], argv[2]);
        write(fd, request, strlen(request));
        if ((n = readn(fd, reply, nbytes)) != nbytes) {
          fprintf(stderr, "server return %d bytes\n", n);
        }
        close(fd);
      }
      printf("child %d done\n", i);
      exit(0);
    }
  }
  while (wait(NULL) > 0)
    continue;
  if (errno != ECHILD) {
    perror("wait error");
    exit(-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x6,-0x8(%rbp)
je     121b <main+0x4b>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%ecx
mov    $0x400,%esi
lea    0xdd3(%rip),%rdx
call   1070 <snprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1365 <main+0x195>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    1352 <main+0x182>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    133c <main+0x16c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1040 <tcp_connect@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x443c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x4438(%rbp)
lea    -0x430(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x443c(%rbp),%edi
mov    -0x4438(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
lea    -0x4430(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1080 <readn@plt>
mov    %eax,-0x30(%rbp)
cmp    -0x28(%rbp),%eax
je     1326 <main+0x156>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
lea    0xd19(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1293 <main+0xc3>
mov    -0x14(%rbp),%esi
lea    0xd0a(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    1357 <main+0x187>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    126d <main+0x9d>
jmp    136a <main+0x19a>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <wait@plt>
cmp    $0x0,%rax
jle    1382 <main+0x1b2>
jmp    136a <main+0x19a>
mov    0x2c4f(%rip),%rax
mov    (%rax),%rax
mov    0x2c3d(%rip),%rcx
cmp    (%rcx),%rax
je     13b2 <main+0x1e2>
lea    0xcbc(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
add    $0x4440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4408,%rsp
mov    %rsi,%r14
cmp    $0x6,%edi
jne    131a <main+0x14a>
mov    0x18(%r14),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r12d
mov    0x20(%r14),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
mov    0x28(%r14),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
lea    0xe1d(%rip),%rdx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %eax,%ecx
call   1070 <snprintf@plt>
test   %r12d,%r12d
jle    1250 <main+0x80>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     128a <main+0xba>
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    1230 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
call   10e0 <wait@plt>
test   %rax,%rax
jg     1250 <main+0x80>
mov    0x2d75(%rip),%rax
mov    (%rax),%rax
mov    0x2d63(%rip),%rcx
cmp    (%rcx),%rax
jne    133e <main+0x16e>
xor    %eax,%eax
add    $0x4408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
jle    1305 <main+0x135>
mov    %rsp,%r12
jmp    12ad <main+0xdd>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r13d,%edi
call   1090 <close@plt>
add    $0xffffffff,%ebp
je     1305 <main+0x135>
mov    0x8(%r14),%rdi
mov    0x10(%r14),%rsi
call   1040 <tcp_connect@plt>
mov    %eax,%r13d
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r13d,%edi
lea    0x400(%rsp),%rsi
mov    %r15d,%edx
call   1080 <readn@plt>
cmp    %r15d,%eax
je     12a0 <main+0xd0>
mov    0x2cef(%rip),%rcx
mov    (%rcx),%edi
lea    0xd3e(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    12a0 <main+0xd0>
lea    0xd44(%rip),%rdi
mov    %ebx,%esi
call   1060 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    0x2cbf(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xcd3(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    0xd1a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [52 x i8] c"Usage: %s <ip> <port> <children> <loops> <request>\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [24 x i8] c"server return %d bytes\0A\00"
@.str.3 = [15 x i8] c"child %d done\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.4 = [11 x i8] c"wait error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [1024 x i8]
%15 = alloca [16384 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 6
br i1 %17, label %18, label %25
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %9
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 4
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %10
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 5
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %11
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%39 = load i32, i32* %11
%40 = call i32 @snprintf(i8* %38, i32 1024, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %39)
store i32 0, i32* %6
br label %41
41: ; preds = %87, %25
%42 = load i32, i32* %6
%43 = load i32, i32* %9
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %90
45: ; preds = %41
%46 = call i32 (...) @fork()
store i32 %46, i32* %12
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %86
48: ; preds = %45
store i32 0, i32* %7
br label %49
49: ; preds = %79, %48
%50 = load i32, i32* %7
%51 = load i32, i32* %10
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %82
53: ; preds = %49
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
%60 = call i32 @tcp_connect(i8* %56, i8* %59)
store i32 %60, i32* %8
%61 = load i32, i32* %8
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
%65 = call i32 @write(i32 %61, i8* %62, i32 %64)
%66 = load i32, i32* %8
%67 = getelementptr inbounds [16384 x i8], [16384 x i8]* %15, i64 0, i64 0
%68 = load i32, i32* %11
%69 = call i32 @readn(i32 %66, i8* %67, i32 %68)
store i32 %69, i32* %13
%70 = load i32, i32* %11
%71 = icmp ne i32 %69, %70
br i1 %71, label %72, label %76
72: ; preds = %53
%73 = load i32, i32* @stderr
%74 = load i32, i32* %13
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %72, %53
%77 = load i32, i32* %8
%78 = call i32 @close(i32 %77)
br label %79
79: ; preds = %76
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 1
store i32 %81, i32* %7
br label %49
82: ; preds = %49
%83 = load i32, i32* %6
%84 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %83)
%85 = call i32 @exit(i32 0)
unreachable
86: ; preds = %45
br label %87
87: ; preds = %86
%88 = load i32, i32* %6
%89 = add nsw i32 %88, 1
store i32 %89, i32* %6
br label %41
90: ; preds = %41
br label %91
91: ; preds = %94, %90
%92 = call i64 @wait(i32* null)
%93 = icmp sgt i64 %92, 0
br i1 %93, label %94, label %95
94: ; preds = %91
br label %91
95: ; preds = %91
%96 = load i64, i64* @errno
%97 = load i64, i64* @ECHILD
%98 = icmp ne i64 %96, %97
br i1 %98, label %99, label %102
99: ; preds = %95
%100 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%101 = call i32 @exit(i32 -1)
unreachable
102: ; preds = %95
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [52 x i8] c"Usage: %s <ip> <port> <children> <loops> <request>\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [24 x i8] c"server return %d bytes\0A\00"
@.str.3 = [15 x i8] c"child %d done\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.4 = [11 x i8] c"wait error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [16384 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 6
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 4
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 5
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = call i32 @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = icmp sgt i32 %16, 0
br i1 %24, label %25, label %56
25: ; preds = %13, %53
%26 = phi i32 [ %54, %53 ], [ 0, %13 ]
%27 = call i32 (...) @fork()
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %53
29: ; preds = %25
%30 = icmp sgt i32 %19, 0
br i1 %30, label %31, label %50
31: ; preds = %29
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = getelementptr inbounds i8*, i8** %1, i64 2
br label %34
34: ; preds = %31, %46
%35 = phi i32 [ 0, %31 ], [ %48, %46 ]
%36 = load i8*, i8** %32
%37 = load i8*, i8** %33
%38 = call i32 @tcp_connect(i8* %36, i8* %37)
%39 = call i32 @strlen(i8* %5)
%40 = call i32 @write(i32 %38, i8* %5, i32 %39)
%41 = call i32 @readn(i32 %38, i8* %6, i32 %22)
%42 = icmp eq i32 %41, %22
br i1 %42, label %46, label %43
43: ; preds = %34
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %46
46: ; preds = %43, %34
%47 = call i32 @close(i32 %38)
%48 = add nuw nsw i32 %35, 1
%49 = icmp eq i32 %48, %19
br i1 %49, label %50, label %34
50: ; preds = %46, %29
%51 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %25
%54 = add nuw nsw i32 %26, 1
%55 = icmp eq i32 %54, %16
br i1 %55, label %56, label %25
56: ; preds = %53, %13
br label %57
57: ; preds = %56, %57
%58 = call i64 @wait(i32* null)
%59 = icmp sgt i64 %58, 0
br i1 %59, label %57, label %60
60: ; preds = %57
%61 = load i64, i64* @errno
%62 = load i64, i64* @ECHILD
%63 = icmp eq i64 %61, %62
br i1 %63, label %67, label %64
64: ; preds = %60
%65 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%66 = call i32 @exit(i32 -1)
unreachable
67: ; preds = %60
ret i32 0
}