#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*/ server_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ RAND_MAX;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  srand(time(NULL));
  unsigned int count = 0;
  int sockfd, portn, i, n, numbers;
  double random;
  struct sockaddr_in server_addr;
  struct hostent *server;
  char buffer[256];
  if (argc == 2 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) {
    printf("Usage: ./app_client <server> <port> <number of numbers to "
           "generate>\n");
    return 0;
  }
  if (argc != 4) {
    perror("Arguments specified wrongly. See --help for usage.");
    exit(1);
  } else {
    server = gethostbyname(argv[1]);
    if (server == NULL) {
      fprintf(stderr, "Error, no such host\n");
      exit(0);
    }
    portn = atoi(argv[2]);
    numbers = atoi(argv[3]);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("Error opening socket");
    exit(1);
  }
  bzero((char *)&server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&server_addr.sin_addr.s_addr,
        server->h_length);
  server_addr.sin_port = htons(portn);
  if (connect(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) <
      0) {
    perror("Error connecting to host");
    exit(1);
  }
  for (i = 0; i < numbers; i++) {
    bzero(buffer, 256);
    random = (double)rand() / (double)RAND_MAX;
    count += 1 + (int)(10 * random);
    sprintf(buffer, "%i", count);
    printf("Client sending %s...\n", buffer);
    n = write(sockfd, buffer, strlen(buffer));
    if (n < 0) {
      error("Error writing to socket");
      exit(1);
    }
    bzero(buffer, 256);
    n = read(sockfd, buffer, 255);
    if (n < 0) {
      perror("Error reading from socket");
      exit(1);
    }
    printf("%s", buffer);
  }
  bzero(buffer, 256);
  sprintf(buffer, "0");
  printf("Client sending %s...\n", buffer);
  n = write(sockfd, buffer, strlen(buffer));
  if (n < 0) {
    error("Error writing to socket");
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    12de <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd6f(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     12c4 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd59(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12de <main+0x8e>
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15ed <main+0x39d>
cmpl   $0x4,-0x8(%rbp)
je     12fe <main+0xae>
lea    0xd68(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1336 <main+0xe6>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1140 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
mov    0x2c62(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1391 <main+0x141>
lea    0xd1d(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
lea    -0x40(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x2c42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x40(%rbp),%rsi
add    $0x4,%rsi
mov    -0x48(%rbp),%rax
mov    (%rax),%edx
call   10e0 <bcopy@plt>
mov    -0x1c(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xc,%edx
call   1150 <connect@plt>
cmp    $0x0,%rax
jge    1402 <main+0x1b2>
lea    0xcc1(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1553 <main+0x303>
lea    -0x150(%rbp),%rdi
mov    $0x100,%esi
call   1110 <bzero@plt>
mov    $0x0,%al
call   1160 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2ba7(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xbb1(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%eax
add    $0x1,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x150(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xc5b(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0x150(%rbp),%rsi
lea    0xc49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x15c(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x158(%rbp)
lea    -0x150(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x15c(%rbp),%edi
mov    -0x158(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    14e8 <main+0x298>
lea    0xc0d(%rip),%rdi
call   10f0 <error@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
lea    -0x150(%rbp),%rdi
mov    $0x100,%esi
call   1110 <bzero@plt>
mov    -0x18(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0xff,%edx
call   1080 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1530 <main+0x2e0>
lea    0xbdd(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
lea    -0x150(%rbp),%rsi
lea    0xbda(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1409 <main+0x1b9>
lea    -0x150(%rbp),%rdi
mov    $0x100,%esi
call   1110 <bzero@plt>
lea    -0x150(%rbp),%rdi
lea    0xba9(%rip),%rsi
mov    $0x0,%al
call   1130 <sprintf@plt>
lea    -0x150(%rbp),%rsi
lea    0xb49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x16c(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    -0x150(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x16c(%rbp),%edi
mov    -0x168(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    15de <main+0x38e>
lea    0xb0d(%rip),%rdi
call   10f0 <error@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
xor    %edi,%edi
call   10e0 <time@plt>
mov    %eax,%edi
call   10a0 <srand@plt>
cmp    $0x4,%ebx
je     12d1 <main+0x71>
cmp    $0x2,%ebx
jne    14e0 <main+0x280>
mov    0x8(%rbp),%rbx
lea    0xd6b(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     12c0 <main+0x60>
lea    0xd5f(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    14e0 <main+0x280>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
jmp    14a0 <main+0x240>
mov    0x8(%rbp),%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     14e9 <main+0x289>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
call   1130 <atoi@plt>
mov    %eax,%r15d
mov    0x18(%rbp),%rdi
call   1130 <atoi@plt>
mov    %eax,%ebp
mov    0x2ce4(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2cb9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
test   %eax,%eax
js     1505 <main+0x2a5>
mov    %eax,%r14d
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rsi
lea    0x4(%rsp),%rdi
mov    (%rbx),%edx
call   10f0 <memmove@plt>
mov    %r15d,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   1160 <connect@plt>
test   %rax,%rax
js     150e <main+0x2ae>
test   %ebp,%ebp
jle    1449 <main+0x1e9>
lea    0x10(%rsp),%rbx
lea    0xd08(%rip),%r12
lea    0xd49(%rip),%r13
xor    %r15d,%r15d
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x100,%esi
call   1120 <bzero@plt>
xor    %eax,%eax
call   1170 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2c2d(%rip),%rax
xorps  %xmm1,%xmm1
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
mulsd  0xc39(%rip),%xmm0
cvttsd2si %xmm0,%eax
lea    0x1(%r15,%rax,1),%r15d
mov    %rbx,%rdi
lea    0xcae(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1140 <sprintf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
js     14b4 <main+0x254>
mov    %rbx,%rdi
mov    $0x100,%esi
call   1120 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1090 <read@plt>
test   %eax,%eax
js     14ca <main+0x26a>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0xffffffff,%ebp
jne    1390 <main+0x130>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1120 <bzero@plt>
movw   $0x30,0x10(%rsp)
lea    0xc22(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
jns    1498 <main+0x238>
lea    0xc0e(%rip),%rdi
call   1100 <error@plt>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbe6(%rip),%rdi
call   1100 <error@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    0xbe8(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    0xb2b(%rip),%rdi
jmp    14d1 <main+0x271>
mov    0x2ae0(%rip),%rax
mov    (%rax),%edi
lea    0xb4c(%rip),%rsi
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
lea    0xb4e(%rip),%rdi
jmp    14d1 <main+0x271>
lea    0xb5a(%rip),%rdi
jmp    14d1 <main+0x271>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [69 x i8] c"Usage: ./app_client <server> <port> <number of numbers to generate>\0A\00"
@.str.3 = [51 x i8] c"Arguments specified wrongly. See --help for usage.\00"
@stderr = global i32 0
@.str.4 = [21 x i8] c"Error, no such host\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [21 x i8] c"Error opening socket\00"
@.str.6 = [25 x i8] c"Error connecting to host\00"
@RAND_MAX = global i64 0
@.str.7 = [3 x i8] c"%i\00"
@.str.8 = [22 x i8] c"Client sending %s...\0A\00"
@.str.9 = [24 x i8] c"Error writing to socket\00"
@.str.10 = [26 x i8] c"Error reading from socket\00"
@.str.11 = [3 x i8] c"%s\00"
@.str.12 = [2 x i8] c"0\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 double
%13 = alloca %struct.sockaddr_in
%14 = alloca %struct.hostent*
%15 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = call i32 @time(i32* null)
%17 = call i32 @srand(i32 %16)
store i32 0, i32* %6
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %34
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strcmp(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %26, %20
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %164
34: ; preds = %26, %2
%35 = load i32, i32* %4
%36 = icmp ne i32 %35, 4
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %34
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call %struct.hostent* @gethostbyname(i8* %43)
store %struct.hostent* %44, %struct.hostent** %14
%45 = load %struct.hostent*, %struct.hostent** %14
%46 = icmp eq %struct.hostent* %45, null
br i1 %46, label %47, label %51
47: ; preds = %40
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %40
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %8
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 3
%58 = load i8*, i8** %57
%59 = call i32 @atoi(i8* %58)
store i32 %59, i32* %11
br label %60
60: ; preds = %51
%61 = load i32, i32* @AF_INET
%62 = load i32, i32* @SOCK_STREAM
%63 = call i32 @socket(i32 %61, i32 %62, i32 0)
store i32 %63, i32* %7
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %60
%69 = bitcast %struct.sockaddr_in* %13 to i8*
%70 = call i32 @bzero(i8* %69, i32 12)
%71 = load i32, i32* @AF_INET
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %71, i32* %72
%73 = load %struct.hostent*, %struct.hostent** %14
%74 = getelementptr inbounds %struct.hostent, %struct.hostent* %73, i32 0, i32 1
%75 = load i64, i64* %74
%76 = inttoptr i64 %75 to i8*
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%78 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %77, i32 0, i32 0
%79 = bitcast i32* %78 to i8*
%80 = load %struct.hostent*, %struct.hostent** %14
%81 = getelementptr inbounds %struct.hostent, %struct.hostent* %80, i32 0, i32 0
%82 = load i32, i32* %81
%83 = call i32 @bcopy(i8* %76, i8* %79, i32 %82)
%84 = load i32, i32* %8
%85 = call i32 @htons(i32 %84)
%86 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
store i32 %85, i32* %86
%87 = load i32, i32* %7
%88 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%89 = call i64 @connect(i32 %87, %struct.sockaddr* %88, i32 12)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %68
%92 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %68
store i32 0, i32* %9
br label %95
95: ; preds = %142, %94
%96 = load i32, i32* %9
%97 = load i32, i32* %11
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %145
99: ; preds = %95
%100 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%101 = call i32 @bzero(i8* %100, i32 256)
%102 = call i64 (...) @rand()
%103 = sitofp i64 %102 to double
%104 = load i64, i64* @RAND_MAX
%105 = sitofp i64 %104 to double
%106 = fdiv double %103, %105
store double %106, double* %12
%107 = load double, double* %12
%108 = fmul double 1.000000e+01, %107
%109 = fptosi double %108 to i32
%110 = add nsw i32 1, %109
%111 = load i32, i32* %6
%112 = add i32 %111, %110
store i32 %112, i32* %6
%113 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%114 = load i32, i32* %6
%115 = call i32 (i8*, i8*, ...) @sprintf(i8* %113, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %114)
%116 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %116)
%118 = load i32, i32* %7
%119 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%120 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%121 = call i32 @strlen(i8* %120)
%122 = call i32 @write(i32 %118, i8* %119, i32 %121)
store i32 %122, i32* %10
%123 = load i32, i32* %10
%124 = icmp slt i32 %123, 0
br i1 %124, label %125, label %128
125: ; preds = %99
%126 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%127 = call i32 @exit(i32 1)
unreachable
128: ; preds = %99
%129 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%130 = call i32 @bzero(i8* %129, i32 256)
%131 = load i32, i32* %7
%132 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%133 = call i32 @read(i32 %131, i8* %132, i32 255)
store i32 %133, i32* %10
%134 = load i32, i32* %10
%135 = icmp slt i32 %134, 0
br i1 %135, label %136, label %139
136: ; preds = %128
%137 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
%138 = call i32 @exit(i32 1)
unreachable
139: ; preds = %128
%140 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %140)
br label %142
142: ; preds = %139
%143 = load i32, i32* %9
%144 = add nsw i32 %143, 1
store i32 %144, i32* %9
br label %95
145: ; preds = %95
%146 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%147 = call i32 @bzero(i8* %146, i32 256)
%148 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%149 = call i32 (i8*, i8*, ...) @sprintf(i8* %148, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%150 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %150)
%152 = load i32, i32* %7
%153 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%154 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%155 = call i32 @strlen(i8* %154)
%156 = call i32 @write(i32 %152, i8* %153, i32 %155)
store i32 %156, i32* %10
%157 = load i32, i32* %10
%158 = icmp slt i32 %157, 0
br i1 %158, label %159, label %161
159: ; preds = %145
%160 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
br label %161
161: ; preds = %159, %145
%162 = load i32, i32* %7
%163 = call i32 @close(i32 %162)
store i32 0, i32* %3
br label %164
164: ; preds = %161, %32
%165 = load i32, i32* %3
ret i32 %165
}

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 }
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.3 = [51 x i8] c"Arguments specified wrongly. See --help for usage.\00"
@stderr = global i32 0
@.str.4 = [21 x i8] c"Error, no such host\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [21 x i8] c"Error opening socket\00"
@.str.6 = [25 x i8] c"Error connecting to host\00"
@RAND_MAX = global i64 0
@.str.7 = [3 x i8] c"%i\00"
@.str.8 = [22 x i8] c"Client sending %s...\0A\00"
@.str.9 = [24 x i8] c"Error writing to socket\00"
@.str.10 = [26 x i8] c"Error reading from socket\00"
@.str.11 = [3 x i8] c"%s\00"
@str = [68 x i8] c"Usage: ./app_client <server> <port> <number of numbers to generate>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
switch i32 %0, label %19 [
i32 2, label %9
i32 4, label %22
]
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14, %9
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @str, i64 0, i64 0))
br label %109
19: ; preds = %14, %2
%20 = tail call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call %struct.hostent* @gethostbyname(i8* %24)
%26 = icmp eq %struct.hostent* %25, null
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%30 = tail call i32 @exit(i32 0)
unreachable
31: ; preds = %22
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = tail call i32 @atoi(i8* %33)
%35 = getelementptr inbounds i8*, i8** %1, i64 3
%36 = load i8*, i8** %35
%37 = tail call i32 @atoi(i8* %36)
%38 = load i32, i32* @AF_INET
%39 = load i32, i32* @SOCK_STREAM
%40 = tail call i32 @socket(i32 %38, i32 %39, i32 0)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %31
%43 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %31
%46 = call i32 @bzero(i8* %7, i32 12)
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %47, i32* %48
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i64 0, i32 1
%50 = load i64, i64* %49
%51 = inttoptr i64 %50 to i8*
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%53 = bitcast i32* %52 to i8*
%54 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i64 0, i32 0
%55 = load i32, i32* %54
%56 = tail call i32 @htons(i32 %34)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %56, i32* %57
%58 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%59 = call i64 @connect(i32 %40, %struct.sockaddr* %58, i32 12)
%60 = icmp slt i64 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %45
%62 = icmp sgt i32 %37, 0
br i1 %62, label %66, label %98
63: ; preds = %45
%64 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %61, %94
%67 = phi i32 [ %78, %94 ], [ 0, %61 ]
%68 = phi i32 [ %96, %94 ], [ 0, %61 ]
%69 = call i32 @bzero(i8* %8, i32 256)
%70 = call i64 (...) @rand()
%71 = sitofp i64 %70 to double
%72 = load i64, i64* @RAND_MAX
%73 = sitofp i64 %72 to double
%74 = fdiv double %71, %73
%75 = fmul double %74, 1.000000e+01
%76 = fptosi double %75 to i32
%77 = add i32 %67, 1
%78 = add i32 %77, %76
%79 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %78)
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %8)
%81 = call i32 @strlen(i8* %8)
%82 = call i32 @write(i32 %40, i8* %8, i32 %81)
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %66
%85 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %66
%88 = call i32 @bzero(i8* %8, i32 256)
%89 = call i32 @read(i32 %40, i8* %8, i32 255)
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %87
%92 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %87
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %8)
%96 = add nuw nsw i32 %68, 1
%97 = icmp eq i32 %96, %37
br i1 %97, label %98, label %66
98: ; preds = %94, %61
%99 = call i32 @bzero(i8* %8, i32 256)
%100 = bitcast [256 x i8]* %4 to i16*
store i16 48, i16* %100
%101 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %8)
%102 = call i32 @strlen(i8* %8)
%103 = call i32 @write(i32 %40, i8* %8, i32 %102)
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %98
%106 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
br label %107
107: ; preds = %105, %98
%108 = call i32 @close(i32 %40)
br label %109
109: ; preds = %107, %17
ret i32 0
}