#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 sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ saddr;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int make_dgram_client_socket();
int /*<<< orphan*/ make_internet_address(char *, int /*<<< orphan*/,
                                         struct sockaddr_in *);
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int ac, char *av[]) {
  int sock;
  char *msg;
  struct sockaddr_in saddr;
  if (ac != 4) {
    fprintf(stderr, "useage: dgsend host port 'message'\n");
    exit(1);
  }
  msg = av[3];
  if ((sock = make_dgram_client_socket()) == -1) {
    perror("Can`t make socket");
    exit(2);
  };
  make_internet_address(av[1], atoi(av[2]), &saddr);
  if (sendto(sock, msg, strlen(msg), 0, (struct sockaddr *)&saddr,
             sizeof(saddr)) == -1) {
    {
      perror("sendto failed");
      exit(3);
    };
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11bf <main+0x3f>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <make_dgram_client_socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f4 <main+0x74>
lea    0xe3f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
lea    -0x28(%rbp),%rdx
call   1040 <make_internet_address@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1050 <sendto@plt>
cmp    $0xffffffff,%eax
jne    126c <main+0xec>
lea    0xdd9(%rip),%rdi
call   1080 <perror@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    11f1 <main+0x71>
mov    %rsi,%rbx
mov    0x18(%rsi),%r14
xor    %eax,%eax
call   1070 <make_dgram_client_socket@plt>
cmp    $0xffffffff,%eax
je     1210 <main+0x90>
mov    %eax,%r15d
mov    0x8(%rbx),%rbp
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %rsp,%rbx
mov    %rbp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1040 <make_internet_address@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    $0x4,%r9d
call   1050 <sendto@plt>
cmp    $0xffffffff,%eax
je     1226 <main+0xa6>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe0d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xe09(%rip),%rdi
call   1080 <perror@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [36 x i8] c"useage: dgsend host port 'message'\0A\00"
@.str.1 = [18 x i8] c"Can`t make socket\00"
@.str.2 = [14 x i8] c"sendto failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 3
%18 = load i8*, i8** %17
store i8* %18, i8** %7
%19 = call i32 (...) @make_dgram_client_socket()
store i32 %19, i32* %6
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 2)
unreachable
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = call i32 @make_internet_address(i8* %27, i32 %31, %struct.sockaddr_in* %8)
%33 = load i32, i32* %6
%34 = load i8*, i8** %7
%35 = load i8*, i8** %7
%36 = call i32 @strlen(i8* %35)
%37 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%38 = call i32 @sendto(i32 %33, i8* %34, i32 %36, i32 0, %struct.sockaddr* %37, i32 4)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %24
%41 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 3)
unreachable
43: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [36 x i8] c"useage: dgsend host port 'message'\0A\00"
@.str.1 = [18 x i8] c"Can`t make socket\00"
@.str.2 = [14 x i8] c"sendto failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 4
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 3
%12 = load i8*, i8** %11
%13 = tail call i32 (...) @make_dgram_client_socket()
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %10
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = call i32 @make_internet_address(i8* %20, i32 %23, %struct.sockaddr_in* %3)
%25 = call i32 @strlen(i8* %12)
%26 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%27 = call i32 @sendto(i32 %13, i8* %12, i32 %25, i32 0, %struct.sockaddr* %26, i32 4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %18
%30 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 3)
unreachable
32: ; preds = %18
ret i32 0
}