#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*/ print_sent_message(void const *, unsigned char);
unsigned char safewrite(int, void const *, unsigned char);
int write_sf_packet(int fd, const void *packet, int len) {
  unsigned char l = len;
  if (safewrite(fd, &l, 1) != 1 || safewrite(fd, packet, l) != l)
    return -1;
  print_sent_message(packet, l);
  return 0;
}


x86 assembly (clang, -O0):
<write_sf_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1030 <safewrite@plt>
movzbl %al,%eax
cmp    $0x1,%eax
jne    1174 <write_sf_packet+0x54>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
movzbl -0x15(%rbp),%edx
call   1030 <safewrite@plt>
movzbl %al,%eax
movzbl -0x15(%rbp),%ecx
cmp    %ecx,%eax
je     1180 <write_sf_packet+0x60>
movl   $0xffffffff,-0x4(%rbp)
jmp    1194 <write_sf_packet+0x74>
mov    -0x10(%rbp),%rdi
movzbl -0x15(%rbp),%esi
call   1040 <print_sent_message@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_sf_packet>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %dl,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <safewrite@plt>
mov    $0xffffffff,%ebp
cmp    $0x1,%al
jne    116b <write_sf_packet+0x4b>
movzbl 0xf(%rsp),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <safewrite@plt>
cmp    0xf(%rsp),%al
jne    116b <write_sf_packet+0x4b>
movzbl %al,%esi
mov    %r14,%rdi
call   1040 <print_sent_message@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @write_sf_packet(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = trunc i32 %9 to i8
store i8 %10, i8* %8
%11 = load i32, i32* %5
%12 = call zeroext i8 @safewrite(i32 %11, i8* %8, i8 zeroext 1)
%13 = zext i8 %12 to i32
%14 = icmp ne i32 %13, 1
br i1 %14, label %24, label %15
15: ; preds = %3
%16 = load i32, i32* %5
%17 = load i8*, i8** %6
%18 = load i8, i8* %8
%19 = call zeroext i8 @safewrite(i32 %16, i8* %17, i8 zeroext %18)
%20 = zext i8 %19 to i32
%21 = load i8, i8* %8
%22 = zext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %15, %3
store i32 -1, i32* %4
br label %29
25: ; preds = %15
%26 = load i8*, i8** %6
%27 = load i8, i8* %8
%28 = call i32 @print_sent_message(i8* %26, i8 zeroext %27)
store i32 0, i32* %4
br label %29
29: ; preds = %25, %24
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @write_sf_packet(i32 %0, i8* %1, i32 %2) {
%4 = alloca i8
%5 = trunc i32 %2 to i8
store i8 %5, i8* %4
%6 = call zeroext i8 @safewrite(i32 %0, i8* %4, i8 zeroext 1)
%7 = icmp eq i8 %6, 1
br i1 %7, label %8, label %15
8: ; preds = %3
%9 = load i8, i8* %4
%10 = call zeroext i8 @safewrite(i32 %0, i8* %1, i8 zeroext %9)
%11 = load i8, i8* %4
%12 = icmp eq i8 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @print_sent_message(i8* %1, i8 zeroext %10)
br label %15
15: ; preds = %3, %8, %13
%16 = phi i32 [ 0, %13 ], [ -1, %8 ], [ -1, %3 ]
ret i32 %16
}