#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 /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serveraddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ dg_cli(int /*<<< orphan*/, int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  int sockfd[20] = {-1};
  struct sockaddr_in serveraddr;
  int i;
  if (3 != argc) {
    printf("argument error\n");
    return -1;
  }
  int cliCnt = atoi(argv[1]);
  for (i = 0; i < cliCnt; ++i) {
    sockfd[i] = socket(AF_INET, SOCK_DGRAM, 0);
    bzero(&serveraddr, sizeof(serveraddr));
    serveraddr.sin_family = AF_INET;
    inet_pton(AF_INET, argv[1], &serveraddr.sin_addr);
    serveraddr.sin_port = htons(9877);
    dg_cli(stdin, sockfd[i], (struct sockaddr *)&serveraddr,
           sizeof(serveraddr));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
movl   $0xffffffff,-0x60(%rbp)
mov    $0x3,%eax
cmp    -0x8(%rbp),%eax
je     11d6 <main+0x56>
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <main+0x115>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x78(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x78(%rbp),%eax
jge    128e <main+0x10e>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ecx
movslq -0x74(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
lea    -0x70(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x70(%rbp),%rdx
add    $0x4,%rdx
call   1060 <inet_pton@plt>
mov    $0x2695,%edi
call   1030 <htons@plt>
mov    %eax,-0x70(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
movslq -0x74(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    -0x70(%rbp),%rdx
mov    $0xc,%ecx
call   1080 <dg_cli@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11ed <main+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jne    1216 <main+0xa6>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    1229 <main+0xb9>
mov    %eax,%ebp
mov    0x2e44(%rip),%r14
lea    0x8(%rsp),%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%r13d
mov    %r12,%rdi
mov    $0xc,%esi
call   1060 <bzero@plt>
mov    (%r14),%edi
mov    %edi,0x10(%rsp)
mov    0x8(%r15),%rsi
lea    0xc(%rsp),%rdx
call   1050 <inet_pton@plt>
mov    $0x2695,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    %r13d,%esi
mov    %r12,%rdx
mov    $0xc,%ecx
call   1070 <dg_cli@plt>
add    $0xffffffff,%ebp
jne    11b0 <main+0x40>
jmp    122b <main+0xbb>
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    122b <main+0xbb>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"argument error\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i32]
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [20 x i32]* %6 to i8*
%11 = bitcast i8* %10 to <{ i32, [19 x i32] }>*
%12 = getelementptr inbounds <{ i32, [19 x i32] }>, <{ i32, [19 x i32] }>* %11, i32 0, i32 0
store i32 -1, i32* %12
%13 = load i32, i32* %4
%14 = icmp ne i32 3, %13
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %55
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %9
store i32 0, i32* %8
br label %22
22: ; preds = %51, %17
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %54
26: ; preds = %22
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_DGRAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %31
store i32 %29, i32* %32
%33 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %34, i32* %35
%36 = load i32, i32* @AF_INET
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%41 = call i32 @inet_pton(i32 %36, i8* %39, i32* %40)
%42 = call i32 @htons(i32 9877)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %42, i32* %43
%44 = load i32, i32* @stdin
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [20 x i32], [20 x i32]* %6, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%50 = call i32 @dg_cli(i32 %44, i32 %48, %struct.sockaddr* %49, i32 12)
br label %51
51: ; preds = %26
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %22
54: ; preds = %22
store i32 0, i32* %3
br label %55
55: ; preds = %54, %15
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stdin = global i32 0
@str = [15 x i8] c"argument error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %32
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %32
13: ; preds = %8
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %18
18: ; preds = %13, %18
%19 = phi i32 [ 0, %13 ], [ %30, %18 ]
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%24 = load i32, i32* @AF_INET
store i32 %24, i32* %14
%25 = load i8*, i8** %9
%26 = call i32 @inet_pton(i32 %24, i8* %25, i32* %15)
%27 = call i32 @htons(i32 9877)
store i32 %27, i32* %16
%28 = load i32, i32* @stdin
%29 = call i32 @dg_cli(i32 %28, i32 %22, %struct.sockaddr* %17, i32 12)
%30 = add nuw nsw i32 %19, 1
%31 = icmp eq i32 %30, %11
br i1 %31, label %32, label %18
32: ; preds = %18, %8, %6
%33 = phi i32 [ -1, %6 ], [ 0, %8 ], [ 0, %18 ]
ret i32 %33
}