#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*/ printf(char *, ...);
int strlen(void *);
int write(int, void *, int);
void ServerWrite(int fd, short ev, void *arg) {
  if (!arg) {
    printf("ServerWrite err!arg null\n");
    return;
  }
  int len = strlen(arg);
  if (len <= 0) {
    printf("ServerWrite err!len:%d\n", len);
    return;
  }
  int wlen = write(fd, arg, len);
  if (wlen < len) {
    printf("not all data write back to client!wlen:%d len:%d \n", wlen, len);
  }
}


x86 assembly (clang, -O0):
<ServerWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <ServerWrite+0x34>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11c2 <ServerWrite+0x92>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1190 <ServerWrite+0x60>
mov    -0x14(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11c2 <ServerWrite+0x92>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c2 <ServerWrite+0x92>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ServerWrite>:
push   %rbp
push   %r14
push   %rbx
test   %rdx,%rdx
je     1184 <ServerWrite+0x44>
mov    %rdx,%rbx
mov    %edi,%r14d
mov    %rdx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1194 <ServerWrite+0x54>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
jge    11a8 <ServerWrite+0x68>
lea    0xea3(%rip),%rdi
mov    %eax,%esi
mov    %ebp,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <printf@plt>
lea    0xec0(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>
lea    0xe65(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <printf@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"ServerWrite err!arg null\0A\00"
@.str.1 = [24 x i8] c"ServerWrite err!len:%d\0A\00"
@.str.2 = [51 x i8] c"not all data write back to client!wlen:%d len:%d \0A\00"
define void @ServerWrite(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %33
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %33
21: ; preds = %13
%22 = load i32, i32* %4
%23 = load i8*, i8** %6
%24 = load i32, i32* %7
%25 = call i32 @write(i32 %22, i8* %23, i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %8
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %21
%30 = load i32, i32* %8
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %31)
br label %33
33: ; preds = %11, %18, %29, %21
ret void
}

LLVM IR (-O2):
@.str.1 = [24 x i8] c"ServerWrite err!len:%d\0A\00"
@.str.2 = [51 x i8] c"not all data write back to client!wlen:%d len:%d \0A\00"
@str = [25 x i8] c"ServerWrite err!arg null\00"
define void @ServerWrite(i32 %0, i16 signext %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %17
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %2)
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %17
12: ; preds = %7
%13 = tail call i32 @write(i32 %0, i8* %2, i32 %8)
%14 = icmp slt i32 %13, %8
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %8)
br label %17
17: ; preds = %10, %15, %12, %5
ret void
}