#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sendbuf;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  struct sockaddr_in addr;
  int sock;
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
  }
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr("192.168.169.102");
  addr.sin_port = htons(1235);
  char sendbuf[20] = {'\0'};
  int length = sizeof(sendbuf) / sizeof(char);
  while (1) {
    strcpy(sendbuf, "hello i am client");
    sendto(sock, sendbuf, length, 0, (struct sockaddr *)&addr, sizeof(addr));
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11c7 <main+0x47>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe2d(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x4d3,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
movl   $0x14,-0x44(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x24(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    1206 <main+0x86>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e67(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1211 <main+0xa1>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe61(%rip),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x4d3,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
lea    0xe44(%rip),%r14
lea    0x10(%rsp),%rbx
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    11e0 <main+0x70>
lea    0xde8(%rip),%rdi
call   1070 <perror@plt>
jmp    1199 <main+0x29>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [16 x i8] c"192.168.169.102\00"
@.str.2 = [18 x i8] c"hello i am client\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [20 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %7
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = call i32 @htons(i32 1235)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %22, i32* %23
%24 = bitcast [20 x i8]* %8 to i8*
store i32 20, i32* %9
br label %25
25: ; preds = %16, %25
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* %7
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%30 = load i32, i32* %9
%31 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%32 = call i32 @sendto(i32 %28, i8* %29, i32 %30, i32 0, %struct.sockaddr* %31, i32 12)
%33 = call i32 @sleep(i32 1)
br label %25
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [16 x i8] c"192.168.169.102\00"
@.str.2 = [18 x i8] c"hello i am client\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [20 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 1235)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %17, i32* %18
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %21
21: ; preds = %21, %12
%22 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @sendto(i32 %8, i8* %19, i32 20, i32 0, %struct.sockaddr* %20, i32 12)
%24 = call i32 @sleep(i32 1)
br label %21
}