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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connecttoDNSserver(struct sockaddr_in *);
int /*<<< orphan*/ createDNSquery(char *, char *);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int parseDNSresponse(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recvDNSrespond(int *, char *, struct sockaddr_in);
int returnIP(char *, int);
int /*<<< orphan*/ sendDNSquery(int *, int /*<<< orphan*/, struct sockaddr_in);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  char buffer[512];
  char Url[512];
  int socksd;
  int IPfound = 0;
  struct sockaddr_in server;
  printf("\nPlease enter in the URL: ");
  fgets(Url, sizeof(Url), stdin);
  Url[strlen(Url) - 1] = '\0';
  printf("\nURL: %s\n", Url);
  socksd = socket(AF_INET, SOCK_DGRAM, 0);
  if (socksd < 0)
    error("ERROR opening socket");
  connecttoDNSserver(&server);
  printf("\nDNS Query:\n");
  sendDNSquery(&socksd, createDNSquery(buffer, Url), server);
  printf("\nDNS Response:\n");
  recvDNSrespond(&socksd, buffer, server);
  IPfound = parseDNSresponse(buffer);
  if (IPfound != -1)
    printf("\nIP address for %s : %d.%d.%d.%d\n\n", Url,
           returnIP(buffer, IPfound), returnIP(buffer, IPfound + 1),
           returnIP(buffer, IPfound + 2), returnIP(buffer, IPfound + 3));
  else
    error("No DNS reponse\n");
  close(socksd);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x418(%rbp)
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1090 <fgets@plt>
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    126a <main+0xaa>
lea    0xdc0(%rip),%rdi
call   10c0 <error@plt>
lea    -0x420(%rbp),%rdi
call   10a0 <connecttoDNSserver@plt>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x210(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   10d0 <createDNSquery@plt>
mov    %eax,%esi
mov    -0x420(%rbp),%edx
lea    -0x414(%rbp),%rdi
call   1040 <sendDNSquery@plt>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x210(%rbp),%rsi
mov    -0x420(%rbp),%edx
lea    -0x414(%rbp),%rdi
call   1030 <recvDNSrespond@plt>
lea    -0x210(%rbp),%rdi
call   10b0 <parseDNSresponse@plt>
mov    %eax,-0x418(%rbp)
cmpl   $0xffffffff,-0x418(%rbp)
je     1392 <main+0x1d2>
lea    -0x410(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x418(%rbp),%esi
call   1060 <returnIP@plt>
mov    %eax,-0x42c(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x418(%rbp),%esi
add    $0x1,%esi
call   1060 <returnIP@plt>
mov    %eax,-0x428(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x418(%rbp),%esi
add    $0x2,%esi
call   1060 <returnIP@plt>
mov    %eax,-0x424(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x418(%rbp),%esi
add    $0x3,%esi
call   1060 <returnIP@plt>
mov    -0x438(%rbp),%rsi
mov    -0x42c(%rbp),%edx
mov    -0x428(%rbp),%ecx
mov    -0x424(%rbp),%r8d
mov    %eax,%r9d
lea    0xcd1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    139e <main+0x1de>
lea    0xce1(%rip),%rdi
call   10c0 <error@plt>
mov    -0x414(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
lea    0xe1a(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xdfd(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
jns    1255 <main+0x85>
lea    0xdd5(%rip),%rdi
call   10d0 <error@plt>
lea    0x8(%rsp),%rdi
call   10b0 <connecttoDNSserver@plt>
lea    0xe07(%rip),%rdi
call   1040 <puts@plt>
lea    0x210(%rsp),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   10e0 <createDNSquery@plt>
mov    0x8(%rsp),%edx
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
mov    %eax,%esi
call   1050 <sendDNSquery@plt>
lea    0xddf(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <recvDNSrespond@plt>
mov    %rbx,%rdi
call   10c0 <parseDNSresponse@plt>
cmp    $0xffffffff,%eax
je     131c <main+0x14c>
mov    %eax,%ebx
lea    0x210(%rsp),%rbp
mov    %rbp,%rdi
mov    %eax,%esi
call   1070 <returnIP@plt>
mov    %eax,%r14d
lea    0x1(%rbx),%esi
mov    %rbp,%rdi
call   1070 <returnIP@plt>
mov    %eax,%r15d
lea    0x2(%rbx),%esi
mov    %rbp,%rdi
call   1070 <returnIP@plt>
mov    %eax,%r12d
add    $0x3,%ebx
mov    %rbp,%rdi
mov    %ebx,%esi
call   1070 <returnIP@plt>
lea    0xd38(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1328 <main+0x158>
lea    0xd3a(%rip),%rdi
call   10d0 <error@plt>
mov    0xc(%rsp),%edi
call   1090 <close@plt>
mov    $0x1,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@.str = [27 x i8] c"\0APlease enter in the URL: \00"
@stdin = global i32 0
@.str.1 = [10 x i8] c"\0AURL: %s\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.3 = [13 x i8] c"\0ADNS Query:\0A\00"
@.str.4 = [16 x i8] c"\0ADNS Response:\0A\00"
@.str.5 = [35 x i8] c"\0AIP address for %s : %d.%d.%d.%d\0A\0A\00"
@.str.6 = [16 x i8] c"No DNS reponse\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
store i32 0, i32* %1
store i32 0, i32* %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 512, i32 %9)
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %0
%24 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %0
%26 = call i32 @connecttoDNSserver(%struct.sockaddr_in* %6)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%30 = call i32 @createDNSquery(i8* %28, i8* %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @sendDNSquery(i32* %4, i32 %30, i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @recvDNSrespond(i32* %4, i8* %35, i32 %37)
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%40 = call i32 @parseDNSresponse(i8* %39)
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = icmp ne i32 %41, -1
br i1 %42, label %43, label %61
43: ; preds = %25
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%46 = load i32, i32* %5
%47 = call i32 @returnIP(i8* %45, i32 %46)
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
%51 = call i32 @returnIP(i8* %48, i32 %50)
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 2
%55 = call i32 @returnIP(i8* %52, i32 %54)
%56 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 3
%59 = call i32 @returnIP(i8* %56, i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %44, i32 %47, i32 %51, i32 %55, i32 %59)
br label %63
61: ; preds = %25
%62 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %63
63: ; preds = %61, %43
%64 = load i32, i32* %4
%65 = call i32 @close(i32 %64)
ret i32 1
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@.str = [27 x i8] c"\0APlease enter in the URL: \00"
@stdin = global i32 0
@.str.1 = [10 x i8] c"\0AURL: %s\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.5 = [35 x i8] c"\0AIP address for %s : %d.%d.%d.%d\0A\0A\00"
@.str.6 = [16 x i8] c"No DNS reponse\0A\00"
@str = [12 x i8] c"\0ADNS Query:\00"
@str.7 = [15 x i8] c"\0ADNS Response:\00"
define i32 @main() {
%1 = alloca [512 x i8]
%2 = alloca [512 x i8]
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %6, i32 512, i32 %10)
%12 = call i32 @strlen(i8* %6)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %0
%24 = call i32 @connecttoDNSserver(%struct.sockaddr_in* %4)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%26 = call i32 @createDNSquery(i8* %5, i8* %6)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @sendDNSquery(i32* %3, i32 %26, i32 %28)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
%31 = load i32, i32* %27
%32 = call i32 @recvDNSrespond(i32* %3, i8* %5, i32 %31)
%33 = call i32 @parseDNSresponse(i8* %5)
%34 = icmp eq i32 %33, -1
br i1 %34, label %44, label %35
35: ; preds = %23
%36 = call i32 @returnIP(i8* %5, i32 %33)
%37 = add nuw nsw i32 %33, 1
%38 = call i32 @returnIP(i8* %5, i32 %37)
%39 = add nsw i32 %33, 2
%40 = call i32 @returnIP(i8* %5, i32 %39)
%41 = add nsw i32 %33, 3
%42 = call i32 @returnIP(i8* %5, i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %6, i32 %36, i32 %38, i32 %40, i32 %42)
br label %46
44: ; preds = %23
%45 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %46
46: ; preds = %44, %35
%47 = load i32, i32* %3
%48 = call i32 @close(i32 %47)
ret i32 1
}