#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;
};
struct servent {
  int /*<<< orphan*/ s_port;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
struct servent *getservbyname(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
main(int argc, char **argv) {
  int s, n, len;
  char buf[256];
  struct hostent *hp;
  struct servent *sp;
  struct sockaddr_in sin;
  if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  if ((sp = getservbyname("daytime", "udp")) == NULL) {
    fprintf(stderr, "%s/udp: unknown service.\n", "daytime");
    exit(1);
  }
  while (--argc) {
    if ((hp = gethostbyname(*++argv)) == NULL) {
      fprintf(stderr, "%s: host unknown.\n", *argv);
      continue;
    }
    sin.sin_family = AF_INET;
    sin.sin_port = sp->s_port;
    bcopy(hp->h_addr, &sin.sin_addr, hp->h_length);
    printf("%s: ", *argv);
    fflush(stdout);
    if (sendto(s, buf, 256, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
      perror("sendto");
      continue;
    }
    len = sizeof(sin);
    n = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&sin, &len);
    if (n < 0) {
      perror("recvfrom");
      continue;
    }
    buf[n] = '\0';
    printf("%s\n", buf);
  }
  close(s);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1214 <main+0x54>
lea    0xdfb(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xdec(%rip),%rdi
lea    0xded(%rip),%rsi
call   1040 <getservbyname@plt>
mov    %rax,-0x130(%rbp)
cmp    $0x0,%rax
jne    125e <main+0x9e>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
lea    0xdb8(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    1263 <main+0xa3>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     13c5 <main+0x205>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    12bf <main+0xff>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd78(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1263 <main+0xa3>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x138(%rbp)
mov    -0x130(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x13c(%rbp)
mov    -0x128(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x140(%rbp),%rsi
mov    -0x128(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bcopy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd36(%rip),%rdi
call   1030 <printf@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
lea    -0x140(%rbp),%r8
mov    $0x100,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
cmp    $0x0,%rax
jge    135b <main+0x19b>
lea    0xcf4(%rip),%rdi
call   10c0 <perror@plt>
jmp    1263 <main+0xa3>
movl   $0xc,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
lea    -0x140(%rbp),%r8
mov    $0x100,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    13a1 <main+0x1e1>
lea    0xcb5(%rip),%rdi
call   10c0 <perror@plt>
jmp    1263 <main+0xa3>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rsi
lea    0xc9a(%rip),%rdi
call   1030 <printf@plt>
jmp    1263 <main+0xa3>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbx
mov    %edi,%r15d
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
jns    120a <main+0x4a>
lea    0xe05(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %eax,%ebp
lea    0xdf4(%rip),%rdi
lea    0xdf5(%rip),%rsi
call   1040 <getservbyname@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
jne    124f <main+0x8f>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
lea    0xdc7(%rip),%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmp    $0x1,%r15d
jne    1263 <main+0xa3>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    %r15d,%r13d
mov    $0x1,%r14d
lea    0x10(%rsp),%r12
lea    0x20(%rsp),%r15
jmp    12a2 <main+0xe2>
nopl   0x0(%rax,%rax,1)
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%r14,8),%rdx
lea    0xd99(%rip),%rsi
call   1080 <fprintf@plt>
add    $0x1,%r14
cmp    %r14d,%r13d
je     1255 <main+0x95>
mov    (%rbx,%r14,8),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     1280 <main+0xc0>
mov    0x2d31(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x18(%rsp)
mov    0x8(%rsp),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x14(%rsp)
mov    (%rax),%edx
mov    0x4(%rax),%edi
mov    %r12,%rsi
call   10b0 <bcopy@plt>
mov    (%rbx,%r14,8),%rsi
lea    0xd60(%rip),%rdi
call   1030 <printf@plt>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
test   %rax,%rax
js     1352 <main+0x192>
movl   $0xc,0x4(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
mov    %r12,%r8
lea    0x4(%rsp),%r9
call   10a0 <recvfrom@plt>
test   %eax,%eax
js     1363 <main+0x1a3>
mov    %eax,%eax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xd10(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
jmp    1299 <main+0xd9>
lea    0xcec(%rip),%rdi
call   10c0 <perror@plt>
jmp    1299 <main+0xd9>
lea    0xce2(%rip),%rdi
call   10c0 <perror@plt>
jmp    1299 <main+0xd9>

LLVM IR (-O0):
%struct.hostent = type { i32, i32 }
%struct.servent = type { i32 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [8 x i8] c"daytime\00"
@.str.2 = [4 x i8] c"udp\00"
@stderr = global i32 0
@.str.3 = [26 x i8] c"%s/udp: unknown service.\0A\00"
@.str.4 = [19 x i8] c"%s: host unknown.\0A\00"
@.str.5 = [5 x i8] c"%s: \00"
@stdout = global i32 0
@.str.6 = [7 x i8] c"sendto\00"
@.str.7 = [9 x i8] c"recvfrom\00"
@.str.8 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca %struct.hostent*
%11 = alloca %struct.servent*
%12 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = call %struct.servent* @getservbyname(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
store %struct.servent* %21, %struct.servent** %11
%22 = icmp eq %struct.servent* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
br label %28
28: ; preds = %79, %77, %68, %38, %27
%29 = load i32, i32* %4
%30 = add nsw i32 %29, -1
store i32 %30, i32* %4
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %85
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i32 1
store i8** %34, i8*** %5
%35 = load i8*, i8** %34
%36 = call %struct.hostent* @gethostbyname(i8* %35)
store %struct.hostent* %36, %struct.hostent** %10
%37 = icmp eq %struct.hostent* %36, null
br i1 %37, label %38, label %43
38: ; preds = %32
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = load i8*, i8** %40
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %28
43: ; preds = %32
%44 = load i32, i32* @AF_INET
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %44, i32* %45
%46 = load %struct.servent*, %struct.servent** %11
%47 = getelementptr inbounds %struct.servent, %struct.servent* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i32 %48, i32* %49
%50 = load %struct.hostent*, %struct.hostent** %10
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%54 = load %struct.hostent*, %struct.hostent** %10
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @bcopy(i32 %52, i32* %53, i32 %56)
%58 = load i8**, i8*** %5
%59 = load i8*, i8** %58
%60 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %59)
%61 = load i32, i32* @stdout
%62 = call i32 @fflush(i32 %61)
%63 = load i32, i32* %6
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%65 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%66 = call i64 @sendto(i32 %63, i8* %64, i32 256, i32 0, %struct.sockaddr* %65, i32 12)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %43
%69 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %28
70: ; preds = %43
store i32 12, i32* %8
%71 = load i32, i32* %6
%72 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%73 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%74 = call i32 @recvfrom(i32 %71, i8* %72, i32 256, i32 0, %struct.sockaddr* %73, i32* %8)
store i32 %74, i32* %7
%75 = load i32, i32* %7
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %70
%78 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %28
79: ; preds = %70
%80 = load i32, i32* %7
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %81
store i8 0, i8* %82
%83 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%84 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %83)
br label %28
85: ; preds = %28
%86 = load i32, i32* %6
%87 = call i32 @close(i32 %86)
%88 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.servent = type { i32 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [8 x i8] c"daytime\00"
@.str.2 = [4 x i8] c"udp\00"
@stderr = global i32 0
@.str.3 = [26 x i8] c"%s/udp: unknown service.\0A\00"
@.str.4 = [19 x i8] c"%s: host unknown.\0A\00"
@.str.5 = [5 x i8] c"%s: \00"
@stdout = global i32 0
@.str.6 = [7 x i8] c"sendto\00"
@.str.7 = [9 x i8] c"recvfrom\00"
@.str.8 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca %struct.sockaddr_in
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call %struct.servent* @getservbyname(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq %struct.servent* %17, null
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = add nsw i32 %0, -1
%21 = icmp eq i32 %20, 0
br i1 %21, label %71, label %22
22: ; preds = %19
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
%24 = getelementptr inbounds %struct.servent, %struct.servent* %17, i64 0, i32 0
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%27 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %32
28: ; preds = %16
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %22, %43
%33 = phi i32 [ %20, %22 ], [ %44, %43 ]
%34 = phi i8** [ %1, %22 ], [ %35, %43 ]
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call %struct.hostent* @gethostbyname(i8* %36)
%38 = icmp eq %struct.hostent* %37, null
br i1 %38, label %39, label %46
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %35
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %39, %60, %65, %67
%44 = add nsw i32 %33, -1
%45 = icmp eq i32 %44, 0
br i1 %45, label %71, label %32
46: ; preds = %32
%47 = load i32, i32* @AF_INET
store i32 %47, i32* %23
%48 = load i32, i32* %24
store i32 %48, i32* %25
%49 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i64 0, i32 1
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i64 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @bcopy(i32 %50, i32* %26, i32 %52)
%54 = load i8*, i8** %35
%55 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = load i32, i32* @stdout
%57 = call i32 @fflush(i32 %56)
%58 = call i64 @sendto(i32 %11, i8* %7, i32 256, i32 0, %struct.sockaddr* %27, i32 12)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %46
%61 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %43
62: ; preds = %46
store i32 12, i32* %3
%63 = call i32 @recvfrom(i32 %11, i8* %7, i32 256, i32 0, %struct.sockaddr* %27, i32* %3)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
br label %43
67: ; preds = %62
%68 = zext i32 %63 to i64
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %68
store i8 0, i8* %69
%70 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %7)
br label %43
71: ; preds = %43, %19
%72 = call i32 @close(i32 %11)
%73 = call i32 @exit(i32 0)
unreachable
}