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

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
size_t strlen(char *);
int write(int, char *, size_t);
int send_data(int sockfd, char *message) {
  size_t len;
  int nwrite;
  if (message == NULL) {
    printf("invalid data,send nothing\n");
    return -1;
  }
  len = strlen(message);
  if (len == 0) {
    printf("invalid data,send nothing\n");
    return -1;
  }
  nwrite = write(sockfd, message, strlen(message));
  if (nwrite < 0) {
    perror("write");
    return -1;
  }
  return nwrite;
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1172 <send_data+0x32>
lea    0xe9f(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <send_data+0xb3>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <send_data+0x62>
lea    0xe6f(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <send_data+0xb3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ed <send_data+0xad>
lea    0xe3f(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <send_data+0xb3>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %rbx
push   %rax
test   %rsi,%rsi
je     1179 <send_data+0x39>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     1179 <send_data+0x39>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
test   %eax,%eax
jns    118a <send_data+0x4a>
lea    0xe8e(%rip),%rdi
call   1060 <perror@plt>
jmp    1185 <send_data+0x45>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"invalid data,send nothing\0A\00"
@.str.1 = [6 x i8] c"write\00"
define i32 @send_data(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %31
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %31
19: ; preds = %12
%20 = load i32, i32* %4
%21 = load i8*, i8** %5
%22 = load i8*, i8** %5
%23 = call i64 @strlen(i8* %22)
%24 = call i32 @write(i32 %20, i8* %21, i64 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %31
29: ; preds = %19
%30 = load i32, i32* %7
store i32 %30, i32* %3
br label %31
31: ; preds = %29, %27, %17, %10
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"write\00"
@str.2 = [26 x i8] c"invalid data,send nothing\00"
define i32 @send_data(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.2, i64 0, i64 0))
br label %16
6: ; preds = %2
%7 = tail call i64 @strlen(i8* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.2, i64 0, i64 0))
br label %16
11: ; preds = %6
%12 = tail call i32 @write(i32 %0, i8* %1, i64 %7)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %11, %14, %9, %4
%17 = phi i32 [ -1, %4 ], [ -1, %9 ], [ -1, %14 ], [ %12, %11 ]
ret i32 %17
}