#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 nserver {
  int dummy;
};

/* Variables and functions */
int clientSocket(int, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ printf(char *);
int recievePacket(struct nserver *, short, int);
int sendPacket(char, char *, short *, int);
int sendAndRecieve(char type, char *nameserver, char *ipstr,
                   struct nserver *nsrec) {
  short id;
  int client_socket;
  client_socket = clientSocket(53, nameserver);
  printf("Client Socket Set up\n");
  if (sendPacket(type, ipstr, &id, client_socket) == -1) {
    return -1;
  }
  if (recievePacket(nsrec, id, client_socket) == -1) {
    return -1;
  }
  close(client_socket);
  return 0;
}


x86 assembly (clang, -O0):
<sendAndRecieve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x35,%edi
call   1040 <clientSocket@plt>
mov    %eax,-0x28(%rbp)
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x5(%rbp),%al
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%ecx
lea    -0x22(%rbp),%rdx
movsbl %al,%edi
call   1060 <sendPacket@plt>
cmp    $0xffffffff,%eax
jne    11b2 <sendAndRecieve+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <sendAndRecieve+0x99>
mov    -0x20(%rbp),%rdi
mov    -0x22(%rbp),%ax
mov    -0x28(%rbp),%edx
movswl %ax,%esi
call   1070 <recievePacket@plt>
cmp    $0xffffffff,%eax
jne    11da <sendAndRecieve+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <sendAndRecieve+0x99>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendAndRecieve>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %edi,%ebp
mov    $0x35,%edi
call   1040 <clientSocket@plt>
mov    %eax,%ebx
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
lea    0x6(%rsp),%rdx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %ebx,%ecx
call   1060 <sendPacket@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11af <sendAndRecieve+0x5f>
movswl 0x6(%rsp),%esi
mov    %r14,%rdi
mov    %ebx,%edx
call   1070 <recievePacket@plt>
cmp    $0xffffffff,%eax
je     11af <sendAndRecieve+0x5f>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nserver = type { i32 }
@.str = [22 x i8] c"Client Socket Set up\0A\00"
define i32 @sendAndRecieve(i8 signext %0, i8* %1, i8* %2, %struct.nserver* %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.nserver*
%10 = alloca i16
%11 = alloca i32
store i8 %0, i8* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store %struct.nserver* %3, %struct.nserver** %9
%12 = load i8*, i8** %7
%13 = call i32 @clientSocket(i32 53, i8* %12)
store i32 %13, i32* %11
%14 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = load i8, i8* %6
%16 = load i8*, i8** %8
%17 = load i32, i32* %11
%18 = call i32 @sendPacket(i8 signext %15, i8* %16, i16* %10, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 -1, i32* %5
br label %31
21: ; preds = %4
%22 = load %struct.nserver*, %struct.nserver** %9
%23 = load i16, i16* %10
%24 = load i32, i32* %11
%25 = call i32 @recievePacket(%struct.nserver* %22, i16 signext %23, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 -1, i32* %5
br label %31
28: ; preds = %21
%29 = load i32, i32* %11
%30 = call i32 @close(i32 %29)
store i32 0, i32* %5
br label %31
31: ; preds = %28, %27, %20
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
%struct.nserver = type { i32 }
@str = [21 x i8] c"Client Socket Set up\00"
define i32 @sendAndRecieve(i8 signext %0, i8* %1, i8* %2, %struct.nserver* %3) {
%5 = alloca i16
%6 = bitcast i16* %5 to i8*
%7 = tail call i32 @clientSocket(i32 53, i8* %1)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%9 = call i32 @sendPacket(i8 signext %0, i8* %2, i16* %5, i32 %7)
%10 = icmp eq i32 %9, -1
br i1 %10, label %17, label %11
11: ; preds = %4
%12 = load i16, i16* %5
%13 = call i32 @recievePacket(%struct.nserver* %3, i16 signext %12, i32 %7)
%14 = icmp eq i32 %13, -1
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @close(i32 %7)
br label %17
17: ; preds = %11, %4, %15
%18 = phi i32 [ 0, %15 ], [ -1, %4 ], [ -1, %11 ]
ret i32 %18
}