#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;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
scalar_t__ getpeername(int, struct sockaddr *, int *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ memcmp(struct sockaddr_in *, struct sockaddr_in *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int sock;
  struct sockaddr_in addr;
  struct sockaddr_in retaddr;
  socklen_t slen = sizeof(addr);
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    do {
      perror("socket");
      exit(-1);
    } while (0);
    ;
  }
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr("10.10.99.235");
  addr.sin_port = htons(80);
  if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    do {
      perror("connect");
      exit(-1);
    } while (0);
    ;
  }
  printf("connected\n");
  if (getpeername(sock, (struct sockaddr *)&retaddr, &slen) < 0) {
    do {
      perror("getpeername");
      exit(-1);
    } while (0);
    ;
  }
  if (memcmp(&retaddr, &addr, sizeof(addr)) != 0)
    do {
      perror("the addresses aren't the same");
      exit(-1);
    } while (0);
  ;
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc,-0x2c(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11f7 <main+0x57>
jmp    11e1 <main+0x41>
lea    0xe18(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xdfd(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x50,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    1255 <main+0xb5>
jmp    123f <main+0x9f>
lea    0xdce(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdc0(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1030 <getpeername@plt>
cmp    $0x0,%rax
jge    1296 <main+0xf6>
jmp    1280 <main+0xe0>
lea    0xda0(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%rax
je     12cd <main+0x12d>
jmp    12b7 <main+0x117>
lea    0xd75(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movl   $0xc,0x4(%rsp)
mov    0x2e32(%rip),%r14
mov    (%r14),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     125a <main+0xba>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x10(%rsp)
lea    0xe26(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
js     1263 <main+0xc3>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1040 <getpeername@plt>
test   %rax,%rax
js     126c <main+0xcc>
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0xc,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
jne    1275 <main+0xd5>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd9f(%rip),%rdi
jmp    127c <main+0xdc>
lea    0xdaa(%rip),%rdi
jmp    127c <main+0xdc>
lea    0xda9(%rip),%rdi
jmp    127c <main+0xdc>
lea    0xdac(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [13 x i8] c"10.10.99.235\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.3 = [11 x i8] c"connected\0A\00"
@.str.4 = [12 x i8] c"getpeername\00"
@.str.5 = [30 x i8] c"the addresses aren't the same\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
store i32 0, i32* %1
store i32 12, i32* %5
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %0
br label %12
12: ; preds = %11
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; No predecessors!
br label %16
16: ; preds = %15, %0
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = call i32 @htons(i32 80)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* %2
%25 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%26 = call i64 @connect(i32 %24, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %16
br label %29
29: ; preds = %28
%30 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 -1)
unreachable
32: ; No predecessors!
br label %33
33: ; preds = %32, %16
%34 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* %2
%36 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%37 = call i64 @getpeername(i32 %35, %struct.sockaddr* %36, i32* %5)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %33
br label %40
40: ; preds = %39
%41 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 @exit(i32 -1)
unreachable
43: ; No predecessors!
br label %44
44: ; preds = %43, %33
%45 = call i64 @memcmp(%struct.sockaddr_in* %4, %struct.sockaddr_in* %3, i32 12)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %44
br label %48
48: ; preds = %47
%49 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%50 = call i32 @exit(i32 -1)
unreachable
51: ; No predecessors!
br label %52
52: ; preds = %51, %44
%53 = load i32, i32* %2
%54 = call i32 @close(i32 %53)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [13 x i8] c"10.10.99.235\00"
@.str.2 = [8 x i8] c"connect\00"
@.str.4 = [12 x i8] c"getpeername\00"
@.str.5 = [30 x i8] c"the addresses aren't the same\00"
@str = [10 x i8] c"connected\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 80)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = call i64 @connect(i32 %9, %struct.sockaddr* %21, i32 12)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %14
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%29 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%30 = call i64 @getpeername(i32 %9, %struct.sockaddr* %29, i32* %3)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %27
%36 = call i64 @memcmp(%struct.sockaddr_in* %2, %struct.sockaddr_in* %1, i32 12)
%37 = icmp eq i64 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %35
%42 = call i32 @close(i32 %9)
ret i32 0
}