#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*/ remote_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int client_sockfd;
  int len;
  struct sockaddr_in remote_addr;
  int sin_size;
  char buf[1024];
  memset(&remote_addr, 0, sizeof(remote_addr));
  remote_addr.sin_family = AF_INET;
  remote_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  remote_addr.sin_port = htons(8000);
  if ((client_sockfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("socket");
    return 1;
  }
  strcpy(buf, "This is a test message");
  printf("sending: '%s'\n", buf);
  sin_size = sizeof(struct sockaddr_in);
  if ((len = sendto(client_sockfd, buf, strlen(buf), 0,
                    (struct sockaddr *)&remote_addr, sizeof(struct sockaddr))) <
      0) {
    perror("recvfrom");
    return 1;
  }
  close(client_sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xe24(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x1f40,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    122e <main+0x8e>
lea    0xded(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <main+0x131>
lea    -0x430(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x430(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1060 <printf@plt>
movl   $0xc,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x43c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12c2 <main+0x122>
lea    0xd86(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d1 <main+0x131>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xe32(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x1f40,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     1262 <main+0xc2>
mov    %eax,%ebx
lea    0xe07(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xe0a(%rip),%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
xor    %r14d,%r14d
mov    %rsp,%r8
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1080 <sendto@plt>
test   %eax,%eax
js     126b <main+0xcb>
mov    %ebx,%edi
call   1090 <close@plt>
mov    %r14d,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xda1(%rip),%rdi
jmp    1272 <main+0xd2>
lea    0xdc5(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%r14d
jmp    1253 <main+0xb3>

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
@.str = [10 x i8] c"127.0.0.1\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [23 x i8] c"This is a test message\00"
@.str.3 = [15 x i8] c"sending: '%s'\0A\00"
@.str.4 = [9 x i8] c"recvfrom\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 %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %12, i32* %13
%14 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = call i32 @htons(i32 8000)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_DGRAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %42
25: ; preds = %2
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %28)
store i32 12, i32* %9
%30 = load i32, i32* %6
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%35 = call i32 @sendto(i32 %30, i8* %31, i32 %33, i32 0, %struct.sockaddr* %34, i32 4)
store i32 %35, i32* %7
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %25
%38 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %42
39: ; preds = %25
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %39, %37, %23
%43 = load i32, i32* %3
ret i32 %43
}

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
@.str = [10 x i8] c"127.0.0.1\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [23 x i8] c"This is a test message\00"
@.str.3 = [15 x i8] c"sending: '%s'\0A\00"
@.str.4 = [9 x i8] c"recvfrom\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %8, i32* %9
%10 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %10, i32* %11
%12 = call i32 @htons(i32 8000)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %31
20: ; preds = %2
%21 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%23 = call i32 @strlen(i8* %6)
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @sendto(i32 %16, i8* %6, i32 %23, i32 0, %struct.sockaddr* %24, i32 4)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %31
29: ; preds = %20
%30 = call i32 @close(i32 %16)
br label %31
31: ; preds = %29, %27, %18
%32 = phi i32 [ 1, %18 ], [ 1, %27 ], [ 0, %29 ]
ret i32 %32
}