#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 */
typedef int /*<<< orphan*/ temp;
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, size_t, int /*<<< orphan*/, struct sockaddr *, int *);
void recvDNSrespond(int *socksd, char *buffer, struct sockaddr_in serveradd) {
  int n, i, addlen;
  char temp[16];
  int buff = 512;
  bzero(buffer, sizeof(buffer));
  addlen = sizeof(struct sockaddr *);
  n = recvfrom(*socksd, buffer, (size_t)buff, 0, (struct sockaddr *)&serveradd,
               &addlen);
  if (n < 0) {
    error("Couldn't read data on socket\n");
  } else {
    for (i = 0; i < 300; i++) {
      if (i % 16 == 0 && i != 0) {
        printf(" %s\n", temp);
        bzero(temp, sizeof(temp));
      }
      printf(" ");
      printf("%02hhX", buffer[i]);
      if ((int)(buffer[i]) > 32)
        temp[i % 16] = buffer[i];
      else
        temp[i % 16] = '.';
    }
    while (i % 16 != 0) {
      printf("   ");
      i++;
    }
    printf(" %s\n", temp);
  }
}


x86 assembly (clang, -O0):
<recvDNSrespond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edx,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x200,-0x44(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x8,%esi
call   1060 <bzero@plt>
movl   $0x8,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
movslq -0x44(%rbp),%rdx
lea    -0x8(%rbp),%r8
xor    %ecx,%ecx
lea    -0x24(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11aa <recvDNSrespond+0x6a>
lea    0xe60(%rip),%rdi
call   1050 <error@plt>
jmp    12c8 <recvDNSrespond+0x188>
movl   $0x0,-0x20(%rbp)
cmpl   $0x12c,-0x20(%rbp)
jge    1281 <recvDNSrespond+0x141>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11fc <recvDNSrespond+0xbc>
cmpl   $0x0,-0x20(%rbp)
je     11fc <recvDNSrespond+0xbc>
lea    -0x40(%rbp),%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x10,%esi
call   1060 <bzero@plt>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jle    125b <recvDNSrespond+0x11b>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
mov    %cl,-0x40(%rbp,%rax,1)
jmp    126e <recvDNSrespond+0x12e>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
movb   $0x2e,-0x40(%rbp,%rax,1)
jmp    1273 <recvDNSrespond+0x133>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b1 <recvDNSrespond+0x71>
jmp    1286 <recvDNSrespond+0x146>
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12b6 <recvDNSrespond+0x176>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1286 <recvDNSrespond+0x146>
lea    -0x40(%rbp),%rsi
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvDNSrespond>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,0x8(%rsp)
mov    %rsi,%rdi
mov    $0x8,%esi
call   1070 <bzero@plt>
movl   $0x8,0xc(%rsp)
mov    (%r14),%edi
lea    0x8(%rsp),%r8
lea    0xc(%rsp),%r9
mov    $0x200,%edx
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1050 <recvfrom@plt>
test   %eax,%eax
js     1269 <recvDNSrespond+0x119>
lea    0x10(%rsp),%r15
lea    0xe76(%rip),%r12
mov    $0x2e,%r13d
xor    %ebp,%ebp
jmp    11f4 <recvDNSrespond+0xa4>
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
movsbl (%rbx,%rbp,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx,%rbp,1),%eax
cmp    $0x21,%al
cmovl  %r13d,%eax
mov    %al,0x10(%rsp,%r14,1)
add    $0x1,%rbp
cmp    $0x12c,%rbp
je     1225 <recvDNSrespond+0xd5>
mov    %ebp,%r14d
and    $0xf,%r14d
test   %rbp,%rbp
je     11c0 <recvDNSrespond+0x70>
test   %r14d,%r14d
jne    11c0 <recvDNSrespond+0x70>
lea    0xe12(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    $0x10,%esi
call   1070 <bzero@plt>
jmp    11c0 <recvDNSrespond+0x70>
lea    0xdfe(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdc3(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1275 <recvDNSrespond+0x125>
lea    0xd90(%rip),%rdi
call   1060 <error@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [30 x i8] c"Couldn't read data on socket\0A\00"
@.str.1 = [5 x i8] c" %s\0A\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [7 x i8] c"%02hhX\00"
@.str.4 = [4 x i8] c" \00"
define void @recvDNSrespond(i32* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [16 x i8]
%11 = alloca i32
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %2, i32* %12
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 512, i32* %11
%13 = load i8*, i8** %6
%14 = call i32 @bzero(i8* %13, i32 8)
store i32 8, i32* %9
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = load i8*, i8** %6
%18 = load i32, i32* %11
%19 = sext i32 %18 to i64
%20 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%21 = call i32 @recvfrom(i32 %16, i8* %17, i64 %19, i32 0, %struct.sockaddr* %20, i32* %9)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %3
%25 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %89
26: ; preds = %3
store i32 0, i32* %8
br label %27
27: ; preds = %74, %26
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 300
br i1 %29, label %30, label %77
30: ; preds = %27
%31 = load i32, i32* %8
%32 = srem i32 %31, 16
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%41 = call i32 @bzero(i8* %40, i32 16)
br label %42
42: ; preds = %37, %34, %30
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%44 = load i8*, i8** %6
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %49)
%51 = load i8*, i8** %6
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp sgt i32 %56, 32
br i1 %57, label %58, label %68
58: ; preds = %42
%59 = load i8*, i8** %6
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = load i32, i32* %8
%65 = srem i32 %64, 16
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 %66
store i8 %63, i8* %67
br label %73
68: ; preds = %42
%69 = load i32, i32* %8
%70 = srem i32 %69, 16
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 %71
store i8 46, i8* %72
br label %73
73: ; preds = %68, %58
br label %74
74: ; preds = %73
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
store i32 %76, i32* %8
br label %27
77: ; preds = %27
br label %78
78: ; preds = %82, %77
%79 = load i32, i32* %8
%80 = srem i32 %79, 16
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %78
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%84 = load i32, i32* %8
%85 = add nsw i32 %84, 1
store i32 %85, i32* %8
br label %78
86: ; preds = %78
%87 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %86, %24
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [30 x i8] c"Couldn't read data on socket\0A\00"
@.str.1 = [5 x i8] c" %s\0A\00"
@.str.3 = [7 x i8] c"%02hhX\00"
@.str.4 = [4 x i8] c" \00"
define void @recvDNSrespond(i32* nocapture %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %2, i32* %7
%8 = bitcast i32* %5 to i8*
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%10 = tail call i32 @bzero(i8* %1, i32 8)
store i32 8, i32* %5
%11 = load i32, i32* %0
%12 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%13 = call i32 @recvfrom(i32 %11, i8* %1, i64 512, i32 0, %struct.sockaddr* %12, i32* %5)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %46
17: ; preds = %3, %27
%18 = phi i64 [ %38, %27 ], [ 0, %3 ]
%19 = trunc i64 %18 to i32
%20 = and i32 %19, 15
%21 = icmp eq i32 %20, 0
%22 = icmp ne i64 %18, 0
%23 = and i1 %22, %21
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%26 = call i32 @bzero(i8* %9, i32 16)
br label %27
27: ; preds = %24, %17
%28 = call i32 @putchar(i32 32)
%29 = getelementptr inbounds i8, i8* %1, i64 %18
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i8, i8* %29
%34 = icmp sgt i8 %33, 32
%35 = zext i32 %20 to i64
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %35
%37 = select i1 %34, i8 %33, i8 46
store i8 %37, i8* %36
%38 = add nuw nsw i64 %18, 1
%39 = icmp eq i64 %38, 300
br i1 %39, label %40, label %17
40: ; preds = %27
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %46
46: ; preds = %40, %15
ret void
}