#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char const *);
int write(int, char const *, scalar_t__);
int sock_send_string(int fd, const char *string) {
  int err;
  if (!string)
    return -1;
  err = write(fd, string, strlen(string) + 1);
  if (err < 0) {
    fprintf(stderr, "sock_send_string: socket write error\n");
    return err;
  }
  return err;
}


x86 assembly (clang, -O0):
<sock_send_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1156 <sock_send_string+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <sock_send_string+0x83>
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    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ad <sock_send_string+0x7d>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <sock_send_string+0x83>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_send_string>:
push   %rbp
push   %rbx
push   %rax
test   %rsi,%rsi
je     1170 <sock_send_string+0x40>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1175 <sock_send_string+0x45>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1175 <sock_send_string+0x45>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [38 x i8] c"sock_send_string: socket write error\0A\00"
define i32 @sock_send_string(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 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 -1, i32* %3
br label %25
10: ; preds = %2
%11 = load i32, i32* %4
%12 = load i8*, i8** %5
%13 = load i8*, i8** %5
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = call i32 @write(i32 %11, i8* %12, i64 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %10
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* %6
store i32 %22, i32* %3
br label %25
23: ; preds = %10
%24 = load i32, i32* %6
store i32 %24, i32* %3
br label %25
25: ; preds = %23, %19, %9
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [38 x i8] c"sock_send_string: socket write error\0A\00"
define i32 @sock_send_string(i32 %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* %1)
%6 = add nsw i64 %5, 1
%7 = tail call i32 @write(i32 %0, i8* %1, i64 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %4, %2, %9
%13 = phi i32 [ %7, %9 ], [ -1, %2 ], [ %7, %4 ]
ret i32 %13
}