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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int fd, numbytes;
  char recvbuf[100];
  char sendbuf[100];
  struct hostent *he;
  struct sockaddr_in server, client;
  int yes;
  if (argc != 2) {
    printf("Usage: %s <IP Address> \n", argv[0]);
    exit(1);
  }
  if ((he = gethostbyname(argv[1])) == NULL) {
    printf("gethostbyname() error\n");
    exit(1);
  }
  if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    printf("socket() error\n");
    exit(1);
  }
  yes = 1;
  setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(yes));
  bzero(&server, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_port = htons(1234);
  server.sin_addr = *((struct in_addr *)he->h_addr);
  socklen_t len;
  len = sizeof(struct sockaddr_in);
  while (1) {
    printf("input message:");
    fgets(sendbuf, 40, stdin);
    sendto(fd, sendbuf, strlen(sendbuf), 0, (struct sockaddr *)&server, len);
    if ((numbytes = recvfrom(fd, recvbuf, 100, 0, (struct sockaddr *)&server,
                             &len)) == -1) {
      printf("recvfrom() error\n");
      break;
    }
    recvbuf[numbytes] = '\0';
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1202 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0xf8(%rbp)
cmp    $0x0,%rax
jne    1238 <main+0x78>
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1275 <main+0xb5>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x1,-0x11c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
mov    0x2d36(%rip),%rax
mov    (%rax),%edx
lea    -0x11c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0x108(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x100(%rbp)
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %eax,-0x104(%rbp)
mov    -0xf8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x108(%rbp)
movl   $0xc,-0x120(%rbp)
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xf0(%rbp),%rdi
mov    0x2cca(%rip),%rax
mov    (%rax),%edx
mov    $0x28,%esi
call   1090 <fgets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x12c(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0xf0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    %eax,%edx
lea    -0x108(%rbp),%r8
mov    -0x120(%rbp),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x108(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x120(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    13a1 <main+0x1e1>
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13af <main+0x1ef>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
jmp    12f2 <main+0x132>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
cmp    $0x2,%edi
jne    1328 <main+0x158>
mov    0x8(%rsi),%rdi
call   10b0 <gethostbyname@plt>
test   %rax,%rax
je     1343 <main+0x173>
mov    %rax,%r15
mov    0x2dda(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     134c <main+0x17c>
mov    %eax,%ebp
movl   $0x1,0xc(%rsp)
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
mov    0x2d8d(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x4d2,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    (%r15),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
movl   $0xc,0x8(%rsp)
mov    0x2d4b(%rip),%r15
lea    0x90(%rsp),%rbx
lea    0x20(%rsp),%r12
lea    0x8(%rsp),%r13
nop
lea    0xd72(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x28,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    0x8(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1080 <sendto@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r13,%r9
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     1301 <main+0x131>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
jmp    12a0 <main+0xd0>
lea    0xd20(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsi),%rsi
lea    0xcce(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xcfe(%rip),%rdi
jmp    1353 <main+0x183>
lea    0xce6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"Usage: %s <IP Address> \0A\00"
@.str.1 = [23 x i8] c"gethostbyname() error\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [16 x i8] c"socket() error\0A\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [15 x i8] c"input message:\00"
@stdin = global i32 0
@.str.4 = [18 x i8] c"recvfrom() error\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 [100 x i8]
%9 = alloca [100 x i8]
%10 = alloca %struct.hostent*
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call %struct.hostent* @gethostbyname(i8* %26)
store %struct.hostent* %27, %struct.hostent** %10
%28 = icmp eq %struct.hostent* %27, null
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23
%33 = load i32, i32* @AF_INET
%34 = load i32, i32* @SOCK_DGRAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
store i32 %35, i32* %6
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %32
store i32 1, i32* %13
%41 = load i32, i32* %6
%42 = load i32, i32* @SOL_SOCKET
%43 = load i32, i32* @SO_BROADCAST
%44 = call i32 @setsockopt(i32 %41, i32 %42, i32 %43, i32* %13, i32 4)
%45 = call i32 @bzero(%struct.sockaddr_in* %11, i32 12)
%46 = load i32, i32* @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %46, i32* %47
%48 = call i32 @htons(i32 1234)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %48, i32* %49
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%51 = load %struct.hostent*, %struct.hostent** %10
%52 = getelementptr inbounds %struct.hostent, %struct.hostent* %51, i32 0, i32 0
%53 = load i64, i64* %52
%54 = inttoptr i64 %53 to %struct.in_addr*
%55 = bitcast %struct.in_addr* %50 to i8*
%56 = bitcast %struct.in_addr* %54 to i8*
store i32 12, i32* %14
br label %57
57: ; preds = %40, %76
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%60 = load i32, i32* @stdin
%61 = call i32 @fgets(i8* %59, i32 40, i32 %60)
%62 = load i32, i32* %6
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%65 = call i32 @strlen(i8* %64)
%66 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%67 = load i32, i32* %14
%68 = call i32 @sendto(i32 %62, i8* %63, i32 %65, i32 0, %struct.sockaddr* %66, i32 %67)
%69 = load i32, i32* %6
%70 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%71 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%72 = call i32 @recvfrom(i32 %69, i8* %70, i32 100, i32 0, %struct.sockaddr* %71, i32* %14)
store i32 %72, i32* %7
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %76
74: ; preds = %57
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %80
76: ; preds = %57
%77 = load i32, i32* %7
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %78
store i8 0, i8* %79
br label %57
80: ; preds = %74
%81 = load i32, i32* %6
%82 = call i32 @close(i32 %81)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [25 x i8] c"Usage: %s <IP Address> \0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.3 = [15 x i8] c"input message:\00"
@stdin = global i32 0
@str = [17 x i8] c"recvfrom() error\00"
@str.5 = [15 x i8] c"socket() error\00"
@str.6 = [22 x i8] c"gethostbyname() error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = icmp eq i32 %0, 2
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call %struct.hostent* @gethostbyname(i8* %19)
%21 = icmp eq %struct.hostent* %20, null
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_DGRAM
%28 = tail call i32 @socket(i32 %26, i32 %27, i32 0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %25
store i32 1, i32* %6
%34 = load i32, i32* @SOL_SOCKET
%35 = load i32, i32* @SO_BROADCAST
%36 = call i32 @setsockopt(i32 %28, i32 %34, i32 %35, i32* %6, i32 4)
%37 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %38, i32* %39
%40 = call i32 @htons(i32 1234)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %40, i32* %41
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i64 0, i32 0
%43 = load i64, i64* %42
%44 = inttoptr i64 %43 to i32*
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0, i32 0
%46 = load i32, i32* %44
store i32 %46, i32* %45
%47 = bitcast i32* %7 to i8*
store i32 12, i32* %7
%48 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %49
49: ; preds = %61, %33
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* @stdin
%52 = call i32 @fgets(i8* %9, i32 40, i32 %51)
%53 = call i32 @strlen(i8* %9)
%54 = load i32, i32* %7
%55 = call i32 @sendto(i32 %28, i8* %9, i32 %53, i32 0, %struct.sockaddr* %48, i32 %54)
%56 = call i32 @recvfrom(i32 %28, i8* %8, i32 100, i32 0, %struct.sockaddr* %48, i32* %7)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %49
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%60 = call i32 @close(i32 %28)
ret i32 0
61: ; preds = %49
%62 = sext i32 %56 to i64
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %62
store i8 0, i8* %63
br label %49
}