#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_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ port;
typedef int /*<<< orphan*/ buffer_size;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int inet_pton(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int read(int, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int write(int, ...);
int client_getset_info(size_t buffer_size, const char *server_ip,
                       int num_threads, int persist_with_reads) {
  int sfd = 0;
  int port = 20480;
  int ret = 0;
  struct sockaddr_in serv_addr;
  sfd = socket(AF_INET, SOCK_STREAM, 0);
  assert(sfd);
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(port);
  ret = inet_pton(AF_INET, server_ip, &serv_addr.sin_addr);
  assert(ret >= 0);
  ret = connect(sfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
  assert(ret == 0);
  ret = read(sfd, &port, sizeof(port));
  assert(ret == sizeof(port));
  ret = write(sfd, &buffer_size, sizeof(buffer_size));
  assert(ret == sizeof(buffer_size));
  ret = write(sfd, &num_threads, sizeof(int));
  assert(ret == sizeof(int));
  ret = write(sfd, &persist_with_reads, sizeof(int));
  assert(ret == sizeof(int));
  close(sfd);
  return port;
}


x86 assembly (clang, -O0):
<client_getset_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x5000,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <assert@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1090 <inet_pton@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x4,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x1c(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x8,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x1c(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x4,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x4,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client_getset_info>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,0x20(%rsp)
mov    %edx,0xc(%rsp)
mov    %ecx,0x8(%rsp)
movl   $0x5000,0x4(%rsp)
mov    0x2e2e(%rip),%r12
mov    (%r12),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <assert@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    $0x5000,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r12),%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <inet_pton@plt>
not    %eax
shr    $0x1f,%eax
mov    %eax,%edi
call   1080 <assert@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1080 <assert@plt>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1070 <read@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1080 <assert@plt>
lea    0x20(%rsp),%rsi
mov    $0x8,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0x8,%eax
sete   %dil
call   1080 <assert@plt>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1080 <assert@plt>
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <write@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1080 <assert@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x4(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @client_getset_info(i64 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
store i64 %0, i64* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 20480, i32* %10
store i32 0, i32* %11
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = call i32 @assert(i32 %16)
%18 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %19, i32* %20
%21 = load i32, i32* %10
%22 = call i32 @htons(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i32 %22, i32* %23
%24 = load i32, i32* @AF_INET
%25 = load i8*, i8** %6
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%27 = call i32 @inet_pton(i32 %24, i8* %25, i32* %26)
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = icmp sge i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i32, i32* %9
%33 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%34 = call i32 @connect(i32 %32, %struct.sockaddr* %33, i32 12)
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = icmp eq i32 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i32, i32* %9
%40 = call i32 @read(i32 %39, i32* %10, i32 4)
store i32 %40, i32* %11
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = icmp eq i64 %42, 4
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* %9
%47 = call i32 (i32, ...) @write(i32 %46, i64* %5, i64 8)
store i32 %47, i32* %11
%48 = load i32, i32* %11
%49 = sext i32 %48 to i64
%50 = icmp eq i64 %49, 8
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
%53 = load i32, i32* %9
%54 = call i32 (i32, ...) @write(i32 %53, i32* %7, i64 4)
store i32 %54, i32* %11
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = icmp eq i64 %56, 4
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = load i32, i32* %9
%61 = call i32 (i32, ...) @write(i32 %60, i32* %8, i64 4)
store i32 %61, i32* %11
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = icmp eq i64 %63, 4
%65 = zext i1 %64 to i32
%66 = call i32 @assert(i32 %65)
%67 = load i32, i32* %9
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* %10
ret i32 %69
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @client_getset_info(i64 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
store i64 %0, i64* %5
store i32 %2, i32* %6
store i32 %3, i32* %7
%10 = bitcast i32* %8 to i8*
store i32 20480, i32* %8
%11 = bitcast %struct.sockaddr_in* %9 to i8*
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = tail call i32 @assert(i32 %14)
%16 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 20480)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0
%23 = call i32 @inet_pton(i32 %21, i8* %1, i32* %22)
%24 = xor i32 %23, -1
%25 = lshr i32 %24, 31
%26 = call i32 @assert(i32 %25)
%27 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%28 = call i32 @connect(i32 %14, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 @read(i32 %14, i32* %8, i32 4)
%33 = icmp eq i32 %32, 4
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i32 (i32, ...) @write(i32 %14, i64* %5, i64 8)
%37 = icmp eq i32 %36, 8
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = call i32 (i32, ...) @write(i32 %14, i32* %6, i64 4)
%41 = icmp eq i32 %40, 4
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = call i32 (i32, ...) @write(i32 %14, i32* %7, i64 4)
%45 = icmp eq i32 %44, 4
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = call i32 @close(i32 %14)
%49 = load i32, i32* %8
ret i32 %49
}