#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int fprintf(int /*<<< orphan*/ *, char *, char *, char const *);
scalar_t__ isalpha(char);
int /*<<< orphan*/ strlen(char const *);
int stub1(char const);
int tolower(int);
int toupper(int);
size_t RFC822HeaderWrite(FILE *out, char const *restrict name,
                         char const *restrict value) {
  int (*conv)(int);
  int size;
  char n[strlen(name) + 1];
  char const *s;
  char *d;
  assert(out != NULL);
  assert(name != NULL);
  assert(value != NULL);
  for (conv = (toupper), s = name, d = n;; s++, d++) {
    *d = (*conv)(*s);
    conv = isalpha(*d) ? (tolower) : (toupper);
    if (*d == '\0')
      break;
  }
  size = fprintf(out, "%s: %s\n", n, value);
  if (size < 0)
    size = 0;
  return (size);
}


x86 assembly (clang, -O0):
<RFC822HeaderWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x50(%rbp),%rax
mov    0x2e14(%rip),%rcx
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsbl (%rcx),%edi
call   *%rax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,(%rax)
mov    -0x48(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isalpha@plt>
mov    %rax,%rdx
mov    0x2dd9(%rip),%rax
mov    0x2de2(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1227 <RFC822HeaderWrite+0xe7>
jmp    1249 <RFC822HeaderWrite+0x109>
jmp    122c <RFC822HeaderWrite+0xec>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    11d4 <RFC822HeaderWrite+0x94>
mov    -0x50(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
lea    0xda4(%rip),%rsi
call   1050 <fprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1275 <RFC822HeaderWrite+0x135>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RFC822HeaderWrite>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,-0x30(%rbp)
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
add    $0x1,%r13d
mov    %rsp,%rbx
add    $0xf,%r13
and    $0xfffffffffffffff0,%r13
mov    %rbx,%r14
sub    %r13,%r14
mov    %r14,%rsp
neg    %r13
xor    %edi,%edi
mov    %r15,-0x38(%rbp)
test   %r15,%r15
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,-0x30(%rbp)
setne  %dil
call   1040 <assert@plt>
movsbl (%r12),%edi
call   1070 <toupper@plt>
mov    %al,(%rbx,%r13,1)
movsbl %al,%r13d
mov    %r13d,%edi
call   1060 <isalpha@plt>
test   %r13b,%r13b
je     121b <RFC822HeaderWrite+0xdb>
mov    $0x1,%ebx
mov    0x2e0c(%rip),%r13
mov    0x2df5(%rip),%r15
jmp    120e <RFC822HeaderWrite+0xce>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r12,%rbx,1),%edi
call   *%rcx
mov    %al,(%r14,%rbx,1)
movsbl %al,%edi
call   1060 <isalpha@plt>
cmpb   $0x0,(%r14,%rbx,1)
lea    0x1(%rbx),%rbx
je     121b <RFC822HeaderWrite+0xdb>
mov    %r13,%rcx
test   %rax,%rax
jne    11f0 <RFC822HeaderWrite+0xb0>
mov    %r15,%rcx
jmp    11f0 <RFC822HeaderWrite+0xb0>
lea    0xdde(%rip),%rsi
mov    -0x38(%rbp),%rdi
mov    %r14,%rdx
mov    -0x30(%rbp),%rcx
call   1050 <fprintf@plt>
xor    %ecx,%ecx
test   %eax,%eax
cmovs  %ecx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s: %s\0A\00"
define i64 @RFC822HeaderWrite(i32* %0, i8* noalias %1, i8* noalias %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32 (i32)*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i8, i64 %16
store i64 %16, i64* %10
%19 = load i32*, i32** %4
%20 = icmp ne i32* %19, null
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
store i32 (i32)* @toupper, i32 (i32)** %7
%31 = load i8*, i8** %5
store i8* %31, i8** %11
store i8* %18, i8** %12
br label %32
32: ; preds = %52, %3
%33 = load i32 (i32)*, i32 (i32)** %7
%34 = load i8*, i8** %11
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = call i32 %33(i32 %36)
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %12
store i8 %38, i8* %39
%40 = load i8*, i8** %12
%41 = load i8, i8* %40
%42 = call i64 @isalpha(i8 signext %41)
%43 = icmp ne i64 %42, 0
%44 = zext i1 %43 to i64
%45 = select i1 %43, i32 (i32)* @tolower, i32 (i32)* @toupper
store i32 (i32)* %45, i32 (i32)** %7
%46 = load i8*, i8** %12
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %32
br label %57
51: ; preds = %32
br label %52
52: ; preds = %51
%53 = load i8*, i8** %11
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %11
%55 = load i8*, i8** %12
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %12
br label %32
57: ; preds = %50
%58 = load i32*, i32** %4
%59 = load i8*, i8** %6
%60 = call i32 @fprintf(i32* %58, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %59)
store i32 %60, i32* %8
%61 = load i32, i32* %8
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %57
store i32 0, i32* %8
br label %64
64: ; preds = %63, %57
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = load i8*, i8** %9
ret i64 %66
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s: %s\0A\00"
define i64 @RFC822HeaderWrite(i32* %0, i8* noalias %1, i8* noalias %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = icmp ne i32* %0, null
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = icmp ne i8* %1, null
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = icmp ne i8* %2, null
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = load i8, i8* %1
%18 = sext i8 %17 to i32
%19 = tail call i32 @toupper(i32 %18)
%20 = trunc i32 %19 to i8
store i8 %20, i8* %7
%21 = tail call i64 @isalpha(i8 signext %20)
%22 = icmp eq i8 %20, 0
br i1 %22, label %38, label %23
23: ; preds = %3, %23
%24 = phi i64 [ %35, %23 ], [ %21, %3 ]
%25 = phi i8* [ %30, %23 ], [ %7, %3 ]
%26 = phi i8* [ %29, %23 ], [ %1, %3 ]
%27 = icmp eq i64 %24, 0
%28 = select i1 %27, i32 (i32)* @toupper, i32 (i32)* @tolower
%29 = getelementptr inbounds i8, i8* %26, i64 1
%30 = getelementptr inbounds i8, i8* %25, i64 1
%31 = load i8, i8* %29
%32 = sext i8 %31 to i32
%33 = tail call i32 %28(i32 %32)
%34 = trunc i32 %33 to i8
store i8 %34, i8* %30
%35 = tail call i64 @isalpha(i8 signext %34)
%36 = load i8, i8* %30
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %23
38: ; preds = %23, %3
%39 = call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %2)
%40 = icmp sgt i32 %39, 0
%41 = select i1 %40, i32 %39, i32 0
%42 = zext i32 %41 to i64
ret i64 %42
}