#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 /*<<< orphan*/ va_list;
typedef int /*<<< orphan*/ stupid_buf;
struct sock {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sock_write(struct sock *, char *);
size_t vsnprintf(char *, int, char const *, int /*<<< orphan*/);
int sock_vsendmsg(struct sock *sock, const char *fmt, va_list ap) {
  char stupid_buf[4089];
  size_t len = vsnprintf(stupid_buf, sizeof(stupid_buf), fmt, ap);
  stupid_buf[len++] = '\r';
  stupid_buf[len++] = '\n';
  stupid_buf[len] = '\0';
  sock_write(sock, stupid_buf);
  printf("\033[32m%s\033[0m", stupid_buf);
  return len;
}


x86 assembly (clang, -O0):
<sock_vsendmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0xff9,%esi
call   1030 <vsnprintf@plt>
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x1018(%rbp)
movb   $0xd,-0x1010(%rbp,%rax,1)
0d
mov    -0x1018(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x1018(%rbp)
movb   $0xa,-0x1010(%rbp,%rax,1)
0a
mov    -0x1018(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   1050 <sock_write@plt>
lea    -0x1010(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1018(%rbp),%rax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_vsendmsg>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %edx,%ecx
mov    %rsi,%rdx
mov    %rdi,%r15
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xff9,%esi
call   1030 <vsnprintf@plt>
mov    %rax,%rbx
movw   $0xa0d,(%rsp,%rax,1)
movb   $0x0,0x2(%rsp,%rax,1)
add    $0x2,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <sock_write@plt>
lea    0xe88(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sock = type { i32 }
@.str = [12 x i8] c"\1B[32m%s\1B[0m\00"
define i32 @sock_vsendmsg(%struct.sock* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sock*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [4089 x i8]
%8 = alloca i64
store %struct.sock* %0, %struct.sock** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [4089 x i8], [4089 x i8]* %7, i64 0, i64 0
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i64 @vsnprintf(i8* %9, i32 4089, i8* %10, i32 %11)
store i64 %12, i64* %8
%13 = load i64, i64* %8
%14 = add i64 %13, 1
store i64 %14, i64* %8
%15 = getelementptr inbounds [4089 x i8], [4089 x i8]* %7, i64 0, i64 %13
store i8 13, i8* %15
%16 = load i64, i64* %8
%17 = add i64 %16, 1
store i64 %17, i64* %8
%18 = getelementptr inbounds [4089 x i8], [4089 x i8]* %7, i64 0, i64 %16
store i8 10, i8* %18
%19 = load i64, i64* %8
%20 = getelementptr inbounds [4089 x i8], [4089 x i8]* %7, i64 0, i64 %19
store i8 0, i8* %20
%21 = load %struct.sock*, %struct.sock** %4
%22 = getelementptr inbounds [4089 x i8], [4089 x i8]* %7, i64 0, i64 0
%23 = call i32 @sock_write(%struct.sock* %21, i8* %22)
%24 = getelementptr inbounds [4089 x i8], [4089 x i8]* %7, i64 0, i64 0
%25 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i64, i64* %8
%27 = trunc i64 %26 to i32
ret i32 %27
}

LLVM IR (-O2):
%struct.sock = type { i32 }
@.str = [12 x i8] c"\1B[32m%s\1B[0m\00"
define i32 @sock_vsendmsg(%struct.sock* %0, i8* nocapture %1, i32 %2) {
%4 = alloca [4089 x i8]
%5 = getelementptr inbounds [4089 x i8], [4089 x i8]* %4, i64 0, i64 0
%6 = call i64 @vsnprintf(i8* %5, i32 4089, i8* %1, i32 %2)
%7 = add i64 %6, 1
%8 = getelementptr inbounds [4089 x i8], [4089 x i8]* %4, i64 0, i64 %6
store i8 13, i8* %8
%9 = add i64 %6, 2
%10 = getelementptr inbounds [4089 x i8], [4089 x i8]* %4, i64 0, i64 %7
store i8 10, i8* %10
%11 = getelementptr inbounds [4089 x i8], [4089 x i8]* %4, i64 0, i64 %9
store i8 0, i8* %11
%12 = call i32 @sock_write(%struct.sock* %0, i8* %5)
%13 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %5)
%14 = trunc i64 %9 to i32
ret i32 %14
}