#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 */
typedef int uint16_t;
typedef int /*<<< orphan*/ to;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  void *sin_port;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ me;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
scalar_t__ bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
void *htons(int);
scalar_t__ inet_aton(char *, TYPE_1__ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr const *,
                  int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char *argv[]) {
  struct sockaddr_in to, me;
  int s, slen = sizeof(to);
  if (argc != 4) {
    fprintf(stderr, "Usage: %s <from_port> <to_port> <msg>\n", argv[0]);
    return 1;
  }
  int from_port = atoi(argv[1]);
  int to_port = atoi(argv[2]);
  char *msg = argv[3];
  int msglen = strlen(msg);
  if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
    exit(1);
  memset((char *)&me, 0, sizeof(me));
  me.sin_family = AF_INET;
  me.sin_port = htons((uint16_t)from_port);
  me.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(s, (const struct sockaddr *)&me, sizeof(me)) < 0)
    exit(1);
  memset((char *)&to, 0, sizeof(to));
  to.sin_family = AF_INET;
  to.sin_port = htons(to_port);
  if (inet_aton("127.0.0.1", &to.sin_addr) == 0)
    exit(1);
  if (sendto(s, msg, msglen, 0, (const struct sockaddr *)&to, slen) < 0)
    exit(1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x18,-0x48(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11ff <main+0x4f>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe12(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1350 <main+0x1a0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x5c(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%rdi
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
mov    0x2d67(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jge    126e <main+0xbe>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4c(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x38(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x40(%rbp)
mov    -0x44(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    12ce <main+0x11e>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x50(%rbp),%edi
call   1040 <htons@plt>
mov    %rax,-0x20(%rbp)
lea    -0x28(%rbp),%rsi
lea    0xd24(%rip),%rdi
call   1090 <inet_aton@plt>
cmp    $0x0,%rax
jne    131c <main+0x16c>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x44(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x5c(%rbp),%edx
lea    -0x28(%rbp),%r8
mov    -0x48(%rbp),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
cmp    $0x0,%rax
jge    1349 <main+0x199>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbp
cmp    $0x4,%edi
jne    12d5 <main+0x125>
mov    0x8(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r13d
mov    0x10(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r15d
mov    0x18(%rbp),%r12
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,0x4(%rsp)
mov    0x2def(%rip),%r14
mov    (%r14),%rdi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
mov    0x2dac(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
test   %eax,%eax
js     12cb <main+0x11b>
mov    %eax,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    (%r14),%rax
mov    %rax,0x18(%rsp)
mov    %r13d,%edi
call   1040 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x18,%edx
call   10a0 <bind@plt>
test   %rax,%rax
js     12cb <main+0x11b>
lea    0x20(%rsp),%r13
xor    %ebx,%ebx
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    (%r14),%rax
mov    %rax,0x30(%rsp)
mov    %r15d,%edi
call   1040 <htons@plt>
mov    %rax,0x28(%rsp)
lea    0xd89(%rip),%rdi
mov    %r13,%rsi
call   1090 <inet_aton@plt>
test   %rax,%rax
je     12cb <main+0x11b>
lea    0x20(%rsp),%r8
mov    %ebp,%edi
mov    %r12,%rsi
mov    0x4(%rsp),%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1070 <sendto@plt>
test   %rax,%rax
jns    12f3 <main+0x143>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd17(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Usage: %s <from_port> <to_port> <msg>\0A\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\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 i32
%12 = alloca i8*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 24, i32* %9
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 4
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %85
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %10
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %11
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
store i8* %33, i8** %12
%34 = load i8*, i8** %12
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %13
%36 = load i8*, i8** @AF_INET
%37 = load i32, i32* @SOCK_DGRAM
%38 = load i32, i32* @IPPROTO_UDP
%39 = call i32 @socket(i8* %36, i32 %37, i32 %38)
store i32 %39, i32* %8
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %22
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %22
%44 = bitcast %struct.sockaddr_in* %7 to i8*
%45 = call i32 @memset(i8* %44, i32 0, i32 24)
%46 = load i8*, i8** @AF_INET
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i8* %46, i8** %47
%48 = load i32, i32* %10
%49 = call i8* @htons(i32 %48)
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i8* %49, i8** %50
%51 = load i32, i32* @INADDR_ANY
%52 = call i32 @htonl(i32 %51)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%54 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %53, i32 0, i32 0
store i32 %52, i32* %54
%55 = load i32, i32* %8
%56 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%57 = call i64 @bind(i32 %55, %struct.sockaddr* %56, i32 24)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %43
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %43
%62 = bitcast %struct.sockaddr_in* %6 to i8*
%63 = call i32 @memset(i8* %62, i32 0, i32 24)
%64 = load i8*, i8** @AF_INET
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i8* %64, i8** %65
%66 = load i32, i32* %11
%67 = call i8* @htons(i32 %66)
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i8* %67, i8** %68
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%70 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %struct.TYPE_2__* %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %61
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %61
%75 = load i32, i32* %8
%76 = load i8*, i8** %12
%77 = load i32, i32* %13
%78 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%79 = load i32, i32* %9
%80 = call i64 @sendto(i32 %75, i8* %76, i32 %77, i32 0, %struct.sockaddr* %78, i32 %79)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %74
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %74
store i32 0, i32* %3
br label %85
85: ; preds = %84, %16
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Usage: %s <from_port> <to_port> <msg>\0A\00"
@AF_INET = global i8* null
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32 %0, 4
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %60
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i32 @strlen(i8* %20)
%22 = load i8*, i8** @AF_INET
%23 = load i32, i32* @SOCK_DGRAM
%24 = load i32, i32* @IPPROTO_UDP
%25 = tail call i32 @socket(i8* %22, i32 %23, i32 %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %12
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %12
%30 = call i32 @memset(i8* %6, i32 0, i32 24)
%31 = load i8*, i8** @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i8* %31, i8** %32
%33 = call i8* @htons(i32 %15)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i8* %33, i8** %34
%35 = load i32, i32* @INADDR_ANY
%36 = call i32 @htonl(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %36, i32* %37
%38 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%39 = call i64 @bind(i32 %25, %struct.sockaddr* %38, i32 24)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %29
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %29
%44 = call i32 @memset(i8* %5, i32 0, i32 24)
%45 = load i8*, i8** @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i8* %45, i8** %46
%47 = call i8* @htons(i32 %18)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i8* %47, i8** %48
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%50 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %struct.TYPE_2__* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %43
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %43
%55 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%56 = call i64 @sendto(i32 %25, i8* %20, i32 %21, i32 0, %struct.sockaddr* %55, i32 24)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %54, %8
%61 = phi i32 [ 1, %8 ], [ 0, %54 ]
ret i32 %61
}