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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char abcd[512];
  int sockfd, portno, n;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  char buffer[256];
  printf("Podaj adres IP odbiorcy: ");
  scanf("%s", abcd);
  printf("Podaj numer portu odbiorcy: ");
  scanf("%u", &portno);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    perror("ERROR opening socket");
    exit(1);
  }
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(portno);
  serv_addr.sin_addr.s_addr = inet_addr(abcd);
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    perror("ERROR connecting");
    exit(1);
  }
  bzero(buffer, 256);
  int number = 0;
  do {
    printf("Please enter correct number: ");
    scanf("%s", buffer);
    number = atoi(buffer);
  } while (!(number > 1 && number < 100000));
  n = write(sockfd, buffer, strlen(buffer));
  if (n < 0) {
    perror("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\n", buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x210(%rbp),%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1090 <scanf@plt>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe19(%rip),%rdi
lea    -0x218(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
jge    1271 <main+0xa1>
lea    0xddb(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x220(%rbp)
mov    -0x218(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x224(%rbp)
lea    -0x210(%rbp),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x228(%rbp)
mov    -0x214(%rbp),%edi
lea    -0x228(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    12da <main+0x10a>
lea    0xd87(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x330(%rbp),%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
movl   $0x0,-0x334(%rbp)
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x330(%rbp),%rsi
lea    0xd09(%rip),%rdi
mov    $0x0,%al
call   1090 <scanf@plt>
lea    -0x330(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x334(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x334(%rbp)
mov    %al,-0x335(%rbp)
jle    1352 <main+0x182>
cmpl   $0x186a0,-0x334(%rbp)
setl   %al
mov    %al,-0x335(%rbp)
mov    -0x335(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    12f5 <main+0x125>
mov    -0x214(%rbp),%eax
mov    %eax,-0x344(%rbp)
lea    -0x330(%rbp),%rax
mov    %rax,-0x340(%rbp)
lea    -0x330(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x344(%rbp),%edi
mov    -0x340(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
jge    13c5 <main+0x1f5>
lea    0xccb(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x330(%rbp),%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
mov    -0x214(%rbp),%edi
lea    -0x330(%rbp),%rsi
mov    $0xff,%edx
call   1070 <read@plt>
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
jge    1416 <main+0x246>
lea    0xc92(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x330(%rbp),%rsi
lea    0xc8f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x328,%rsp
lea    0xe0c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe18(%rip),%rdi
lea    0x120(%rsp),%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe14(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
mov    0x2daf(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     1349 <main+0x169>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0xc(%rsp),%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0x120(%rsp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
js     1352 <main+0x172>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
lea    0xdb5(%rip),%r15
lea    0xd65(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <scanf@plt>
mov    %rbx,%rdi
call   10d0 <atoi@plt>
add    $0xfffe7960,%eax
cmp    $0xfffe7962,%eax
jb     12c0 <main+0xe0>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
js     135b <main+0x17b>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1080 <read@plt>
test   %eax,%eax
js     1364 <main+0x184>
lea    0x20(%rsp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x328,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xced(%rip),%rdi
jmp    136b <main+0x18b>
lea    0xcf9(%rip),%rdi
jmp    136b <main+0x18b>
lea    0xd1f(%rip),%rdi
jmp    136b <main+0x18b>
lea    0xd2e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"Podaj adres IP odbiorcy: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [29 x i8] c"Podaj numer portu odbiorcy: \00"
@.str.3 = [3 x i8] c"%u\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [21 x i8] c"ERROR opening socket\00"
@.str.5 = [17 x i8] c"ERROR connecting\00"
@.str.6 = [30 x i8] c"Please enter correct number: \00"
@.str.7 = [24 x i8] c"ERROR writing to socket\00"
@.str.8 = [26 x i8] c"ERROR reading from socket\00"
@.str.9 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.hostent*
%12 = alloca [256 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %8)
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %2
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %28, i32* %29
%30 = load i32, i32* %8
%31 = call i32 @htons(i32 %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%34 = call i32 @inet_addr(i8* %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = load i32, i32* %7
%38 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%39 = call i64 @connect(i32 %37, %struct.sockaddr* %38, i32 12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %27
%42 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %27
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%46 = call i32 @bzero(i8* %45, i32 256)
store i32 0, i32* %13
br label %47
47: ; preds = %59, %44
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%50 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %49)
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%52 = call i32 @atoi(i8* %51)
store i32 %52, i32* %13
br label %53
53: ; preds = %47
%54 = load i32, i32* %13
%55 = icmp sgt i32 %54, 1
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = load i32, i32* %13
%58 = icmp slt i32 %57, 100000
br label %59
59: ; preds = %56, %53
%60 = phi i1 [ false, %53 ], [ %58, %56 ]
%61 = xor i1 %60, true
br i1 %61, label %47, label %62
62: ; preds = %59
%63 = load i32, i32* %7
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = call i32 @write(i32 %63, i8* %64, i32 %66)
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %62
%71 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %62
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%75 = call i32 @bzero(i8* %74, i32 256)
%76 = load i32, i32* %7
%77 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%78 = call i32 @read(i32 %76, i8* %77, i32 255)
store i32 %78, i32* %9
%79 = load i32, i32* %9
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %73
%82 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %73
%85 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %85)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [26 x i8] c"Podaj adres IP odbiorcy: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [29 x i8] c"Podaj numer portu odbiorcy: \00"
@.str.3 = [3 x i8] c"%u\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [21 x i8] c"ERROR opening socket\00"
@.str.5 = [17 x i8] c"ERROR connecting\00"
@.str.6 = [30 x i8] c"Please enter correct number: \00"
@.str.7 = [24 x i8] c"ERROR writing to socket\00"
@.str.8 = [26 x i8] c"ERROR reading from socket\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* %4
%26 = call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %26, i32* %27
%28 = call i32 @inet_addr(i8* %7)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
store i32 %28, i32* %29
%30 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%31 = call i64 @connect(i32 %17, %struct.sockaddr* %30, i32 12)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %22
%34 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %22
%37 = call i32 @bzero(i8* %10, i32 256)
br label %38
38: ; preds = %38, %36
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%41 = call i32 @atoi(i8* %10)
%42 = add i32 %41, -100000
%43 = icmp ult i32 %42, -99998
br i1 %43, label %38, label %44
44: ; preds = %38
%45 = call i32 @strlen(i8* %10)
%46 = call i32 @write(i32 %17, i8* %10, i32 %45)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %44
%52 = call i32 @bzero(i8* %10, i32 256)
%53 = call i32 @read(i32 %17, i8* %10, i32 255)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %51
%59 = call i32 @puts(i8* %10)
ret i32 0
}