#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 */
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
size_t strlen(char const *);
int write(int, char const *, size_t);
size_t send_request(int sock, const char *request) {
  size_t len;
  ssize_t written;
  len = 0;
  while (len != strlen(request)) {
    written = write(sock, (request + len), strlen(request) - len);
    if (written == -1) {
      fprintf(stderr, "Write to wifidog failed: %s\n", strerror(errno));
      exit(1);
    }
    len += written;
  }
  return len;
}


x86 assembly (clang, -O0):
<send_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     120a <send_request+0xba>
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
sub    -0x18(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11f9 <send_request+0xa9>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xe16(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movslq -0x1c(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1167 <send_request+0x17>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_request>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1199 <send_request+0x49>
nopl   0x0(%rax)
lea    (%rbx,%rbp,1),%rsi
sub    %rbp,%rax
mov    %r14d,%edi
mov    %rax,%rdx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     11a1 <send_request+0x51>
cltq
add    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rbp,%rax
jne    1170 <send_request+0x20>
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e38(%rip),%rax
mov    (%rax),%ebx
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe41(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Write to wifidog failed: %s\0A\00"
@errno = global i32 0
define i64 @send_request(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i64 0, i64* %5
br label %7
7: ; preds = %30, %2
%8 = load i64, i64* %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = icmp ne i64 %8, %10
br i1 %11, label %12, label %35
12: ; preds = %7
%13 = load i32, i32* %3
%14 = load i8*, i8** %4
%15 = load i64, i64* %5
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8*, i8** %4
%18 = call i64 @strlen(i8* %17)
%19 = load i64, i64* %5
%20 = sub i64 %18, %19
%21 = call i32 @write(i32 %13, i8* %16, i64 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %30
24: ; preds = %12
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %12
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = load i64, i64* %5
%34 = add i64 %33, %32
store i64 %34, i64* %5
br label %7
35: ; preds = %7
%36 = load i64, i64* %5
ret i64 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Write to wifidog failed: %s\0A\00"
@errno = global i32 0
define i64 @send_request(i32 %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %23, label %8
5: ; preds = %8
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = icmp eq i64 %6, %16
br i1 %7, label %23, label %8
8: ; preds = %2, %5
%9 = phi i64 [ %6, %5 ], [ %3, %2 ]
%10 = phi i64 [ %16, %5 ], [ 0, %2 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = sub i64 %9, %10
%13 = tail call i32 @write(i32 %0, i8* %11, i64 %12)
%14 = icmp eq i32 %13, -1
%15 = sext i32 %13 to i64
%16 = add i64 %10, %15
br i1 %14, label %17, label %5
17: ; preds = %8
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %5, %2
%24 = phi i64 [ 0, %2 ], [ %16, %5 ]
ret i64 %24
}