#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*/ time_t;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ srv_addr;
typedef int socklen_t;
typedef int /*<<< orphan*/ msg;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int /*<<< orphan*/, char *);
int recvfrom(int, void *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, scalar_t__, int /*<<< orphan*/, struct sockaddr const *,
           int);
int /*<<< orphan*/ sleep(int);
int snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  struct sockaddr_in srv_addr, cli_addr;
  int sock_fd, n;
  socklen_t addr_len;
  char buf[4096] = {0};
  assert(argc >= 2);
  sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock_fd < 0) {
    perror("socket");
    exit(-1);
  }
  bzero(&srv_addr, sizeof(srv_addr));
  srv_addr.sin_family = AF_INET;
  srv_addr.sin_port = htons(6666);
  inet_aton(argv[1], &srv_addr.sin_addr);
  addr_len = sizeof(srv_addr);
  int i = 5;
  while (--i) {
    sleep(1);
    time_t t = time(NULL);
    char msg[128] = {0};
    n = snprintf(msg, sizeof(msg) - 1, "%s", ctime(&t));
    msg[n - 1] = '\0';
    n = sendto(sock_fd, msg, strlen(msg) + 1, 0,
               (const struct sockaddr *)&srv_addr, addr_len);
    if (n < 0) {
      perror("sendto");
      break;
    }
    n = recvfrom(sock_fd, (void *)buf, 4096 - 1, 0,
                 (struct sockaddr *)&srv_addr, &addr_len);
    if (n <= 0) {
      perror("recvfrom");
      break;
    } else {
      buf[n - 1] = '\0';
      printf("client: [%s:%hu]:%s\n", inet_ntoa(cli_addr.sin_addr),
             ntohs(cli_addr.sin_port), buf);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1040(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1090 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   10b0 <assert@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1299 <main+0x79>
lea    0xd76(%rip),%rdi
call   1100 <perror@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x1a0a,%edi
call   1060 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   10d0 <inet_aton@plt>
movl   $0xc,-0x3c(%rbp)
movl   $0x5,-0x1044(%rbp)
mov    -0x1044(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1044(%rbp)
cmp    $0x0,%eax
je     1456 <main+0x236>
mov    $0x1,%edi
call   1130 <sleep@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,-0x1048(%rbp)
lea    -0x10d0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1090 <memset@plt>
lea    -0x10d0(%rbp),%rax
mov    %rax,-0x10e8(%rbp)
lea    -0x1048(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x10e8(%rbp),%rdi
mov    %rax,%rcx
mov    $0x7f,%esi
lea    0xcb1(%rip),%rdx
call   1080 <snprintf@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x10d0(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
mov    %eax,-0x10dc(%rbp)
lea    -0x10d0(%rbp),%rax
mov    %rax,-0x10d8(%rbp)
lea    -0x10d0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x10dc(%rbp),%edi
mov    -0x10d8(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x20(%rbp),%r8
mov    -0x3c(%rbp),%r9d
xor    %ecx,%ecx
call   10a0 <sendto@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    13d2 <main+0x1b2>
lea    0xc42(%rip),%rdi
call   1100 <perror@plt>
jmp    1456 <main+0x236>
mov    -0x34(%rbp),%edi
lea    -0x1040(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0xfff,%edx
xor    %ecx,%ecx
lea    -0x3c(%rbp),%r9
call   10e0 <recvfrom@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jg     140e <main+0x1ee>
lea    0xc0d(%rip),%rdi
call   1100 <perror@plt>
jmp    1456 <main+0x236>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x1040(%rbp,%rax,1)
mov    -0x30(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x10f0(%rbp)
mov    -0x2c(%rbp),%edi
call   10f0 <ntohs@plt>
mov    -0x10f0(%rbp),%rsi
mov    %eax,%edx
lea    -0x1040(%rbp),%rcx
lea    0xbce(%rip),%rdi
call   1070 <printf@plt>
jmp    12e2 <main+0xc2>
xor    %eax,%eax
add    $0x10f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10a8,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
lea    0xa0(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1090 <memset@plt>
xor    %edi,%edi
cmp    $0x2,%ebx
setge  %dil
call   10b0 <assert@plt>
mov    0x2d89(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
test   %eax,%eax
js     13e4 <main+0x1c4>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x1a0a,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%r15),%rdi
mov    %r14,%rsi
call   10d0 <inet_aton@plt>
movl   $0xc,0x8(%rsp)
mov    $0xfffffffc,%r13d
lea    0x20(%rsp),%rbp
lea    0xa0(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1130 <sleep@plt>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,0xc(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <ctime@plt>
mov    %rbp,%rdi
mov    $0x7f,%esi
lea    0xcd8(%rip),%rdx
mov    %rax,%rcx
call   1080 <snprintf@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    0x8(%rsp),%r9d
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
mov    %r14,%r8
call   10a0 <sendto@plt>
test   %eax,%eax
js     13c8 <main+0x1a8>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xfff,%edx
xor    %ecx,%ecx
mov    %r14,%r8
lea    0x8(%rsp),%r9
call   10e0 <recvfrom@plt>
test   %eax,%eax
jle    13d6 <main+0x1b6>
add    $0xffffffff,%eax
movb   $0x0,0xa0(%rsp,%rax,1)
call   1030 <inet_ntoa@plt>
mov    %rax,%r12
call   10f0 <ntohs@plt>
lea    0xc7c(%rip),%rdi
mov    %r12,%rsi
mov    %eax,%edx
mov    %r15,%rcx
call   1070 <printf@plt>
inc    %r13d
jne    12d0 <main+0xb0>
xor    %eax,%eax
add    $0x10a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc3b(%rip),%rdi
call   1100 <perror@plt>
jmp    13b4 <main+0x194>
lea    0xc34(%rip),%rdi
call   1100 <perror@plt>
jmp    13b4 <main+0x194>
lea    0xc15(%rip),%rdi
call   1100 <perror@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%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 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"sendto\00"
@.str.3 = [9 x i8] c"recvfrom\00"
@.str.4 = [21 x i8] c"client: [%s:%hu]:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [4096 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [4096 x i8]* %11 to i8*
%16 = load i32, i32* %4
%17 = icmp sge i32 %16, 2
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %2
%29 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %30, i32* %31
%32 = call i32 @htons(i32 6666)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%38 = call i32 @inet_aton(i8* %36, i32* %37)
store i32 12, i32* %10
store i32 5, i32* %12
br label %39
39: ; preds = %88, %28
%40 = load i32, i32* %12
%41 = add nsw i32 %40, -1
store i32 %41, i32* %12
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %89
43: ; preds = %39
%44 = call i32 @sleep(i32 1)
%45 = call i32 @time(i32* null)
store i32 %45, i32* %13
%46 = bitcast [128 x i8]* %14 to i8*
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%48 = call i8* @ctime(i32* %13)
%49 = call i32 @snprintf(i8* %47, i32 127, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %48)
store i32 %49, i32* %9
%50 = load i32, i32* %9
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 %52
store i8 0, i8* %53
%54 = load i32, i32* %8
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %14, i64 0, i64 0
%57 = call i64 @strlen(i8* %56)
%58 = add nsw i64 %57, 1
%59 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%60 = load i32, i32* %10
%61 = call i32 @sendto(i32 %54, i8* %55, i64 %58, i32 0, %struct.sockaddr* %59, i32 %60)
store i32 %61, i32* %9
%62 = load i32, i32* %9
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %43
%65 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %89
66: ; preds = %43
%67 = load i32, i32* %8
%68 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%69 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%70 = call i32 @recvfrom(i32 %67, i8* %68, i32 4095, i32 0, %struct.sockaddr* %69, i32* %10)
store i32 %70, i32* %9
%71 = load i32, i32* %9
%72 = icmp sle i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %66
%74 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %89
75: ; preds = %66
%76 = load i32, i32* %9
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 %78
store i8 0, i8* %79
%80 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%81 = load i32, i32* %80
%82 = call i8* @inet_ntoa(i32 %81)
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%84 = load i32, i32* %83
%85 = call i32 @ntohs(i32 %84)
%86 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%87 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %82, i32 %85, i8* %86)
br label %88
88: ; preds = %75
br label %39
89: ; preds = %73, %64, %39
ret i32 0
}

LLVM IR (-O2):
%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 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"sendto\00"
@.str.3 = [9 x i8] c"recvfrom\00"
@.str.4 = [21 x i8] c"client: [%s:%hu]:%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [4096 x i8]
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%11 = icmp sgt i32 %0, 1
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %23, i32* %24
%25 = tail call i32 @htons(i32 6666)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %25, i32* %26
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%30 = call i32 @inet_aton(i8* %28, i32* %29)
store i32 12, i32* %4
%31 = bitcast i32* %6 to i8*
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %34
34: ; preds = %21, %54
%35 = phi i32 [ 4, %21 ], [ %61, %54 ]
%36 = call i32 @sleep(i32 1)
%37 = call i32 @time(i32* null)
store i32 %37, i32* %6
%38 = call i8* @ctime(i32* %6)
%39 = call i32 @snprintf(i8* %32, i32 127, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%40 = add nsw i32 %39, -1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %41
store i8 0, i8* %42
%43 = call i64 @strlen(i8* %32)
%44 = add nsw i64 %43, 1
%45 = load i32, i32* %4
%46 = call i32 @sendto(i32 %16, i8* %32, i64 %44, i32 0, %struct.sockaddr* %33, i32 %45)
%47 = icmp slt i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %34
%49 = call i32 @recvfrom(i32 %16, i8* %10, i32 4095, i32 0, %struct.sockaddr* %33, i32* %4)
%50 = icmp slt i32 %49, 1
br i1 %50, label %51, label %54
51: ; preds = %48, %34
%52 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %34 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), %48 ]
%53 = call i32 @perror(i8* %52)
br label %63
54: ; preds = %48
%55 = add nsw i32 %49, -1
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 %56
store i8 0, i8* %57
%58 = call i8* @inet_ntoa(i32 undef)
%59 = call i32 @ntohs(i32 undef)
%60 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %58, i32 %59, i8* %10)
%61 = add nsw i32 %35, -1
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %34
63: ; preds = %54, %51
ret i32 0
}