#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;
};

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
int SendEchoMessage(int sock, struct sockaddr_in *pServAddr) {
  char echoString[(255) + 1];
  int echoStringLen;
  int sendMsgLen;
  if (fgets(echoString, (255) + 1, stdin) == NULL) {
    return -1;
  }
  echoStringLen = strlen(echoString);
  if (echoStringLen < 1) {
    fprintf(stderr, "No input string.\n");
    return -1;
  }
  sendMsgLen = sendto(sock, echoString, echoStringLen, 0,
                      (struct sockaddr *)pServAddr, sizeof(*pServAddr));
  if (echoStringLen != sendMsgLen) {
    fprintf(stderr,
            "sendto() sent a different number of bytes than expected\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<SendEchoMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    1182 <SendEchoMessage+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <SendEchoMessage+0xe3>
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x1,-0x114(%rbp)
jge    11c2 <SendEchoMessage+0x82>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <SendEchoMessage+0xe3>
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
mov    -0x10(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1040 <sendto@plt>
mov    %eax,-0x118(%rbp)
mov    -0x114(%rbp),%eax
cmp    -0x118(%rbp),%eax
je     121c <SendEchoMessage+0xdc>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <SendEchoMessage+0xe3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendEchoMessage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     11c2 <SendEchoMessage+0x82>
mov    %rsp,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11a8 <SendEchoMessage+0x68>
mov    %eax,%ebp
mov    %rsp,%rsi
xor    %ebx,%ebx
mov    %r15d,%edi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0x4,%r9d
call   1040 <sendto@plt>
cmp    %eax,%ebp
je     11c2 <SendEchoMessage+0x82>
lea    0xe6c(%rip),%rsi
jmp    11af <SendEchoMessage+0x6f>
lea    0xe51(%rip),%rsi
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@stdin = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"No input string.\0A\00"
@.str.1 = [57 x i8] c"sendto() sent a different number of bytes than expected\0A\00"
define i32 @SendEchoMessage(i32 %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %9, i32 256, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %36
14: ; preds = %2
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %36
22: ; preds = %14
%23 = load i32, i32* %4
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* %7
%26 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%27 = bitcast %struct.sockaddr_in* %26 to %struct.sockaddr*
%28 = call i32 @sendto(i32 %23, i8* %24, i32 %25, i32 0, %struct.sockaddr* %27, i32 4)
store i32 %28, i32* %8
%29 = load i32, i32* %7
%30 = load i32, i32* %8
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %22
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %36
35: ; preds = %22
store i32 0, i32* %3
br label %36
36: ; preds = %35, %32, %19, %13
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@stdin = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"No input string.\0A\00"
@.str.1 = [57 x i8] c"sendto() sent a different number of bytes than expected\0A\00"
define i32 @SendEchoMessage(i32 %0, %struct.sockaddr_in* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %4, i32 256, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %19, label %8
8: ; preds = %2
%9 = call i32 @strlen(i8* %4)
%10 = icmp slt i32 %9, 1
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%13 = call i32 @sendto(i32 %0, i8* %4, i32 %9, i32 0, %struct.sockaddr* %12, i32 4)
%14 = icmp eq i32 %9, %13
br i1 %14, label %19, label %15
15: ; preds = %11, %8
%16 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %8 ], [ getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), %11 ]
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* %16)
br label %19
19: ; preds = %15, %11, %2
%20 = phi i32 [ -1, %2 ], [ 0, %11 ], [ -1, %15 ]
ret i32 %20
}