#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*/ MSG_DONTWAIT;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int send_data(int fd, char *buf) {
  int ret;
  if (strncmp(buf, "*113883#", 8) == 0) {
    printf("say hello\n");
    ret = send(fd, buf, strlen(buf), MSG_DONTWAIT);
    if (ret == -1) {
      perror("say hello error");
      return -1;
    }
    return ret;
  }
  printf("send data to server:%s\n", buf);
  ret = send(fd, buf, strlen(buf), MSG_DONTWAIT);
  if (ret <= 0) {
    perror("send data error!");
  }
  return ret;
}


x86 assembly (clang, -O0):
<send_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ea <send_data+0x9a>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
call   1050 <send@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11df <send_data+0x8f>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <send_data+0xf9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1249 <send_data+0xf9>
mov    -0x10(%rbp),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
mov    0x2dbd(%rip),%rax
mov    (%rax),%ecx
call   1050 <send@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1243 <send_data+0xf3>
lea    0xdfe(%rip),%rdi
call   1070 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_data>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11be <send_data+0x5e>
lea    0xe91(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <send@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     11ee <send_data+0x8e>
lea    0xe75(%rip),%rdi
jmp    1203 <send_data+0xa3>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    0x2e07(%rip),%rcx
mov    (%rcx),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <send@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11f7 <send_data+0x97>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0xffffffff,%ebx
lea    0xe06(%rip),%rdi
call   1080 <perror@plt>
jmp    11ee <send_data+0x8e>

LLVM IR (-O0):
@.str = [9 x i8] c"*113883#\00"
@.str.1 = [11 x i8] c"say hello\0A\00"
@MSG_DONTWAIT = global i32 0
@.str.2 = [16 x i8] c"say hello error\00"
@.str.3 = [24 x i8] c"send data to server:%s\0A\00"
@.str.4 = [17 x i8] c"send data error!\00"
define i32 @send_data(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %4
%13 = load i8*, i8** %5
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = load i32, i32* @MSG_DONTWAIT
%17 = call i32 @send(i32 %12, i8* %13, i32 %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
22: ; preds = %10
%23 = load i32, i32* %6
store i32 %23, i32* %3
br label %39
24: ; preds = %2
%25 = load i8*, i8** %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %4
%28 = load i8*, i8** %5
%29 = load i8*, i8** %5
%30 = call i32 @strlen(i8* %29)
%31 = load i32, i32* @MSG_DONTWAIT
%32 = call i32 @send(i32 %27, i8* %28, i32 %30, i32 %31)
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = icmp sle i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %24
%36 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %24
%38 = load i32, i32* %6
store i32 %38, i32* %3
br label %39
39: ; preds = %37, %22, %20
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [9 x i8] c"*113883#\00"
@MSG_DONTWAIT = global i32 0
@.str.2 = [16 x i8] c"say hello error\00"
@.str.3 = [24 x i8] c"send data to server:%s\0A\00"
@.str.4 = [17 x i8] c"send data error!\00"
@str = [10 x i8] c"say hello\00"
define i32 @send_data(i32 %0, i8* %1) {
%3 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @strlen(i8* %1)
%8 = load i32, i32* @MSG_DONTWAIT
%9 = tail call i32 @send(i32 %0, i8* %1, i32 %7, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %17, label %21
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%13 = tail call i32 @strlen(i8* %1)
%14 = load i32, i32* @MSG_DONTWAIT
%15 = tail call i32 @send(i32 %0, i8* %1, i32 %13, i32 %14)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %11, %5
%18 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), %11 ]
%19 = phi i32 [ -1, %5 ], [ %15, %11 ]
%20 = tail call i32 @perror(i8* %18)
br label %21
21: ; preds = %17, %11, %5
%22 = phi i32 [ %9, %5 ], [ %15, %11 ], [ %19, %17 ]
ret i32 %22
}