#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*/ snprintf(char *, int, char *, char const *, ...);
int /*<<< orphan*/ strcmp(char const *, char *);
int strlen(char const *);
int write_to_fd(int, char *);
ssize_t jasm_write_with_header(int sockfd, const char *__src,
                               const char *data_type, const char *header) {
  if (!header)
    return -10;
  char final[4096];
  size_t last_hdr = strlen(header) - 1;
  if (header[last_hdr] != '\n')
    return -8;
  if (!strcmp(data_type, "data/nodata"))
    snprintf(final, 4096, "Data-Type: %s\nData-Size: 0\n%s\n%s", "data/nodata",
             header, __src);
  else
    snprintf(final, 4096, "Data-Type: %s\nData-Size: %ld\n%s\n%s", data_type,
             strlen(__src), header, __src);
  return write_to_fd(sockfd, final);
}


x86 assembly (clang, -O0):
<jasm_write_with_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1171 <jasm_write_with_header+0x31>
movl   $0xfffffff6,-0x4(%rbp)
jmp    1255 <jasm_write_with_header+0x115>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x1028(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x1028(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11aa <jasm_write_with_header+0x6a>
movl   $0xfffffff8,-0x4(%rbp)
jmp    1255 <jasm_write_with_header+0x115>
mov    -0x18(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11f1 <jasm_write_with_header+0xb1>
lea    -0x1020(%rbp),%rdi
mov    -0x20(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    $0x1000,%esi
lea    0xe2e(%rip),%rdx
lea    0xe1b(%rip),%rcx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    1243 <jasm_write_with_header+0x103>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1038(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x1038(%rbp),%rdi
mov    -0x1030(%rbp),%rcx
mov    %eax,%r8d
mov    -0x20(%rbp),%r9
mov    -0x10(%rbp),%rax
mov    $0x1000,%esi
lea    0xdf5(%rip),%rdx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%edi
lea    -0x1020(%rbp),%rsi
call   1060 <write_to_fd@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jasm_write_with_header>:
test   %rcx,%rcx
je     11b7 <jasm_write_with_header+0x77>
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1018,%rsp
mov    %rcx,%rbx
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %edi,%r14d
mov    %rcx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rcx
mov    $0xfffffff8,%eax
cmpb   $0xa,-0x1(%rcx,%rbx,1)
jne    11ef <jasm_write_with_header+0xaf>
lea    0xe84(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11bd <jasm_write_with_header+0x7d>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r15,(%rsp)
lea    0xe92(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x1000,%esi
mov    %rbp,%rcx
mov    %eax,%r8d
mov    %rbx,%r9
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    11e2 <jasm_write_with_header+0xa2>
mov    $0xfffffff6,%eax
ret
lea    0xe48(%rip),%rdx
lea    0xe35(%rip),%rcx
lea    0x10(%rsp),%rdi
mov    $0x1000,%esi
mov    %rbx,%r8
mov    %r15,%r9
xor    %eax,%eax
call   1040 <snprintf@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
call   1060 <write_to_fd@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"data/nodata\00"
@.str.1 = [33 x i8] c"Data-Type: %s\0AData-Size: 0\0A%s\0A%s\00"
@.str.2 = [35 x i8] c"Data-Type: %s\0AData-Size: %ld\0A%s\0A%s\00"
define i32 @jasm_write_with_header(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [4096 x i8]
%11 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %9
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %4
store i32 -10, i32* %5
br label %48
15: ; preds = %4
%16 = load i8*, i8** %9
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
store i64 %19, i64* %11
%20 = load i8*, i8** %9
%21 = load i64, i64* %11
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %15
store i32 -8, i32* %5
br label %48
27: ; preds = %15
%28 = load i8*, i8** %8
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %27
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%33 = load i8*, i8** %9
%34 = load i8*, i8** %7
%35 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %32, i32 4096, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %34)
br label %44
36: ; preds = %27
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%38 = load i8*, i8** %8
%39 = load i8*, i8** %7
%40 = call i32 @strlen(i8* %39)
%41 = load i8*, i8** %9
%42 = load i8*, i8** %7
%43 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %37, i32 4096, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %38, i32 %40, i8* %41, i8* %42)
br label %44
44: ; preds = %36, %31
%45 = load i32, i32* %6
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%47 = call i32 @write_to_fd(i32 %45, i8* %46)
store i32 %47, i32* %5
br label %48
48: ; preds = %44, %26, %14
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
@.str = [12 x i8] c"data/nodata\00"
@.str.1 = [33 x i8] c"Data-Type: %s\0AData-Size: 0\0A%s\0A%s\00"
@.str.2 = [35 x i8] c"Data-Type: %s\0AData-Size: %ld\0A%s\0A%s\00"
define i32 @jasm_write_with_header(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [4096 x i8]
%6 = icmp eq i8* %3, null
br i1 %6, label %27, label %7
7: ; preds = %4
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @strlen(i8* %3)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %3, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %25
15: ; preds = %7
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %2, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %1)
br label %23
20: ; preds = %15
%21 = tail call i32 @strlen(i8* %1)
%22 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %21, i8* %3, i8* %1)
br label %23
23: ; preds = %20, %18
%24 = call i32 @write_to_fd(i32 %0, i8* %8)
br label %25
25: ; preds = %7, %23
%26 = phi i32 [ %24, %23 ], [ -8, %7 ]
br label %27
27: ; preds = %4, %25
%28 = phi i32 [ %26, %25 ], [ -10, %4 ]
ret i32 %28
}