#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 strlen(char const *);
int write(int, char const *, int);
int send_to_server(int conn, const char *request) {
  int req_len = strlen(request);
  int n;
  n = write(conn, request, req_len);
  if (n < 0) {
    perror("ERROR writing to socket");
    return 0;
  }
  return (n == req_len);
}


x86 assembly (clang, -O0):
<send_to_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    117f <send_to_server+0x4f>
lea    0xe92(%rip),%rdi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1190 <send_to_server+0x60>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_to_server>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1163 <send_to_server+0x33>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
sete   %al
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
jmp    115e <send_to_server+0x2e>

LLVM IR (-O0):
@.str = [24 x i8] c"ERROR writing to socket\00"
define i32 @send_to_server(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %4
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i32 @write(i32 %10, i8* %11, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %23
18: ; preds = %2
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = icmp eq i32 %19, %20
%22 = zext i1 %21 to i32
store i32 %22, i32* %3
br label %23
23: ; preds = %18, %16
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@.str = [24 x i8] c"ERROR writing to socket\00"
define i32 @send_to_server(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @write(i32 %0, i8* %1, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %11
8: ; preds = %2
%9 = icmp eq i32 %4, %3
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ 0, %6 ], [ %10, %8 ]
ret i32 %12
}