#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ myaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    perror("argment count error");
    exit(1);
  }
  int server_fd;
  struct hostent *myhost;
  struct sockaddr_in myaddr;
  myaddr.sin_family = AF_INET;
  myhost = gethostbyname(argv[1]);
  if (!myhost) {
    perror("gethost error");
    exit(1);
  }
  myaddr.sin_addr = *((struct in_addr *)myhost->h_addr);
  myaddr.sin_port = htons(8080);
  char buf[100];
  server_fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (server_fd == -1) {
    perror("socket error");
    exit(1);
  }
  sendto(server_fd, "nice to meet you .", 11, 0, (struct sockaddr *)&myaddr,
         sizeof(myaddr));
  printf("send to success!\n");
  close(server_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b9 <main+0x39>
lea    0xe56(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f7 <main+0x77>
lea    0xe2c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x1f90,%edi
call   1030 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    124c <main+0xcc>
lea    0xde5(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%r8
lea    0xdd5(%rip),%rsi
mov    $0xb,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
lea    0xdcf(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jle    1211 <main+0x91>
mov    0x2e53(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rsi),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     121a <main+0x9a>
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    $0x1f90,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     1223 <main+0xa3>
mov    %eax,%ebx
lea    0xe50(%rip),%rsi
mov    %rsp,%r8
mov    %eax,%edi
mov    $0xb,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xde8(%rip),%rdi
jmp    122a <main+0xaa>
lea    0xdf3(%rip),%rdi
jmp    122a <main+0xaa>
lea    0xdf8(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"argment count error\00"
@AF_INET = global i32 0
@.str.1 = [14 x i8] c"gethost error\00"
@SOCK_DGRAM = global i32 0
@.str.2 = [13 x i8] c"socket error\00"
@.str.3 = [19 x i8] c"nice to meet you .\00"
@.str.4 = [18 x i8] c"send to success!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %16, i32* %17
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call %struct.hostent* @gethostbyname(i8* %20)
store %struct.hostent* %21, %struct.hostent** %7
%22 = load %struct.hostent*, %struct.hostent** %7
%23 = icmp ne %struct.hostent* %22, null
br i1 %23, label %27, label %24
24: ; preds = %15
%25 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %15
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%29 = load %struct.hostent*, %struct.hostent** %7
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to %struct.in_addr*
%33 = bitcast %struct.in_addr* %28 to i8*
%34 = bitcast %struct.in_addr* %32 to i8*
%35 = call i32 @htons(i32 8080)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %35, i32* %36
%37 = load i32, i32* @AF_INET
%38 = load i32, i32* @SOCK_DGRAM
%39 = call i32 @socket(i32 %37, i32 %38, i32 0)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %27
%43 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %27
%46 = load i32, i32* %6
%47 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%48 = call i32 @sendto(i32 %46, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 11, i32 0, %struct.sockaddr* %47, i32 12)
%49 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [20 x i8] c"argment count error\00"
@AF_INET = global i32 0
@.str.1 = [14 x i8] c"gethost error\00"
@SOCK_DGRAM = global i32 0
@.str.2 = [13 x i8] c"socket error\00"
@.str.3 = [19 x i8] c"nice to meet you .\00"
@str = [17 x i8] c"send to success!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call %struct.hostent* @gethostbyname(i8* %13)
%15 = icmp eq %struct.hostent* %14, null
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %8
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i64 0, i32 0
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to i32*
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%24 = load i32, i32* %22
store i32 %24, i32* %23
%25 = tail call i32 @htons(i32 8080)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_DGRAM
%29 = tail call i32 @socket(i32 %27, i32 %28, i32 0)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %19
%32 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %19
%35 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%36 = call i32 @sendto(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 11, i32 0, %struct.sockaddr* %35, i32 12)
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%38 = call i32 @close(i32 %29)
ret i32 0
}