#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 */
char *alloca(int);
int /*<<< orphan*/ base64_encode_str(char *, char *);
int strlen(char *);
scalar_t__ strncasecmp(char const *, char *, int);
int /*<<< orphan*/ swerr(char *, int, char *, char *);
int message_base64_subj(char const *msg, char *out, int maxlen) {
  char const *s;
  char *p;
  int l;
  char *buf;
  buf = alloca(maxlen + 4);
  do {
    if (!(buf))
      swerr(
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/stden/ejudge/refs/heads/master/misctext.c",
          414, "assertion failed: %s", "buf");
  } while (0);
  if (!strncasecmp(msg, "subject:", 8)) {
    s = msg + 8;
    while (1) {
      while (*s == ' ' || *s == '\t')
        s++;
      if (strncasecmp(s, "re:", 3))
        break;
      s += 3;
    }
    if (*s == '\n' || *s == '\r' || !*s)
      s = "(no subject)";
  } else {
    s = "(no subject)";
  }
  for (p = buf, l = maxlen; *s && *s != '\n' && *s != '\r' && l;
       s++, p++, l--) {
    *p = *s;
  }
  if (*s && *s != '\n' && *s != '\r') {
    *p = 0;
    *--p = '.';
    *--p = '.';
    *--p = '.';
  } else {
    *p = 0;
  }
  base64_encode_str(buf, out);
  return strlen(out);
}


x86 assembly (clang, -O0):
<message_base64_subj>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x4,%edi
call   1040 <alloca@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    119c <message_base64_subj+0x4c>
lea    0xe7c(%rip),%rdi
mov    $0x19e,%esi
lea    0xef4(%rip),%rdx
lea    0xf02(%rip),%rcx
call   1050 <swerr@plt>
jmp    11a1 <message_base64_subj+0x51>
mov    -0x8(%rbp),%rdi
lea    0xef1(%rip),%rsi
mov    $0x8,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1289 <message_base64_subj+0x139>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11d1 <message_base64_subj+0x81>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x39(%rbp)
je     11f6 <message_base64_subj+0xa6>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1206 <message_base64_subj+0xb6>
jmp    1217 <message_base64_subj+0xc7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d1 <message_base64_subj+0x81>
mov    -0x20(%rbp),%rdi
lea    0xe84(%rip),%rsi
mov    $0x3,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
je     123b <message_base64_subj+0xeb>
jmp    124c <message_base64_subj+0xfc>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    11cc <message_base64_subj+0x7c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1279 <message_base64_subj+0x129>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
je     1279 <message_base64_subj+0x129>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1284 <message_base64_subj+0x134>
lea    0xe2a(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1294 <message_base64_subj+0x144>
lea    0xe1a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x3a(%rbp)
je     12eb <message_base64_subj+0x19b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x3a(%rbp)
je     12eb <message_base64_subj+0x19b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xd,%ecx
mov    %al,-0x3a(%rbp)
je     12eb <message_base64_subj+0x19b>
cmpl   $0x0,-0x2c(%rbp)
setne  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    12fb <message_base64_subj+0x1ab>
jmp    132d <message_base64_subj+0x1dd>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    12a2 <message_base64_subj+0x152>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     13a2 <message_base64_subj+0x252>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     13a2 <message_base64_subj+0x252>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
je     13a2 <message_base64_subj+0x252>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x2e,-0x1(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x2e,-0x1(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x2e,-0x1(%rax)
jmp    13a9 <message_base64_subj+0x259>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <base64_encode_str@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<message_base64_subj>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbp
mov    %rdi,%r13
lea    0x4(%r15),%edi
call   1040 <alloca@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1194 <message_base64_subj+0x44>
lea    0xe84(%rip),%rdi
lea    0xf01(%rip),%rdx
lea    0xf0f(%rip),%rcx
mov    $0x19e,%esi
call   1050 <swerr@plt>
lea    0xf02(%rip),%rsi
mov    %r13,%rdi
mov    $0x8,%edx
call   1060 <strncasecmp@plt>
lea    0xefb(%rip),%rbx
test   %rax,%rax
jne    1228 <message_base64_subj+0xd8>
mov    %rbp,(%rsp)
add    $0x8,%r13
lea    0xee3(%rip),%rbp
jmp    11d7 <message_base64_subj+0x87>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
mov    %rbx,%r13
mov    %r13,%rbx
movzbl 0x0(%r13),%r14d
cmp    $0x20,%r14b
je     11d0 <message_base64_subj+0x80>
cmp    $0x9,%r14b
je     11d0 <message_base64_subj+0x80>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x3,%edx
call   1060 <strncasecmp@plt>
lea    0x3(%rbx),%r13
test   %rax,%rax
je     11d7 <message_base64_subj+0x87>
cmp    $0xd,%r14b
ja     128a <message_base64_subj+0x13a>
movzbl %r14b,%eax
mov    $0x2401,%ecx
bt     %rax,%rcx
mov    (%rsp),%rbp
jae    1228 <message_base64_subj+0xd8>
lea    0xe82(%rip),%rbx
mov    %r15d,%ecx
xor    %eax,%eax
nopl   (%rax)
movzbl (%rbx,%rax,1),%edx
test   %dl,%dl
je     1259 <message_base64_subj+0x109>
cmp    $0xa,%dl
je     1259 <message_base64_subj+0x109>
cmp    $0xd,%dl
je     1250 <message_base64_subj+0x100>
cmp    %eax,%ecx
je     1250 <message_base64_subj+0x100>
mov    %dl,(%r12,%rax,1)
add    $0x1,%rax
jmp    1230 <message_base64_subj+0xe0>
test   %dl,%dl
je     1259 <message_base64_subj+0x109>
cmp    $0xd,%dl
jne    127f <message_base64_subj+0x12f>
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1070 <base64_encode_str@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strlen@plt>
movl   $0x2e2e2e,-0x3(%r12,%rax,1)
jmp    125e <message_base64_subj+0x10e>
mov    (%rsp),%rbp
jmp    1228 <message_base64_subj+0xd8>

LLVM IR (-O0):
@.str = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/stden/ejudge/refs/heads/master/misctext.c\00"
@.str.1 = [21 x i8] c"assertion failed: %s\00"
@.str.2 = [4 x i8] c"buf\00"
@.str.3 = [9 x i8] c"subject:\00"
@.str.4 = [4 x i8] c"re:\00"
@.str.5 = [13 x i8] c"(no subject)\00"
define i32 @message_base64_subj(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 4
%13 = call i8* @alloca(i32 %12)
store i8* %13, i8** %10
br label %14
14: ; preds = %3
%15 = load i8*, i8** %10
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @swerr(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i32 414, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
br label %20
20: ; preds = %19
%21 = load i8*, i8** %4
%22 = call i64 @strncasecmp(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%23 = icmp ne i64 %22, 0
br i1 %23, label %67, label %24
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 8
store i8* %26, i8** %7
br label %27
27: ; preds = %24, %48
br label %28
28: ; preds = %40, %27
%29 = load i8*, i8** %7
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 32
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load i8*, i8** %7
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 9
br label %38
38: ; preds = %33, %28
%39 = phi i1 [ true, %28 ], [ %37, %33 ]
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %7
br label %28
43: ; preds = %38
%44 = load i8*, i8** %7
%45 = call i64 @strncasecmp(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %43
br label %51
48: ; preds = %43
%49 = load i8*, i8** %7
%50 = getelementptr inbounds i8, i8* %49, i64 3
store i8* %50, i8** %7
br label %27
51: ; preds = %47
%52 = load i8*, i8** %7
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 10
br i1 %55, label %65, label %56
56: ; preds = %51
%57 = load i8*, i8** %7
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 13
br i1 %60, label %65, label %61
61: ; preds = %56
%62 = load i8*, i8** %7
%63 = load i8, i8* %62
%64 = icmp ne i8 %63, 0
br i1 %64, label %66, label %65
65: ; preds = %61, %56, %51
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %66
66: ; preds = %65, %61
br label %68
67: ; preds = %20
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %68
68: ; preds = %67, %66
%69 = load i8*, i8** %10
store i8* %69, i8** %8
%70 = load i32, i32* %6
store i32 %70, i32* %9
br label %71
71: ; preds = %95, %68
%72 = load i8*, i8** %7
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %89
76: ; preds = %71
%77 = load i8*, i8** %7
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp ne i32 %79, 10
br i1 %80, label %81, label %89
81: ; preds = %76
%82 = load i8*, i8** %7
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp ne i32 %84, 13
br i1 %85, label %86, label %89
86: ; preds = %81
%87 = load i32, i32* %9
%88 = icmp ne i32 %87, 0
br label %89
89: ; preds = %86, %81, %76, %71
%90 = phi i1 [ false, %81 ], [ false, %76 ], [ false, %71 ], [ %88, %86 ]
br i1 %90, label %91, label %102
91: ; preds = %89
%92 = load i8*, i8** %7
%93 = load i8, i8* %92
%94 = load i8*, i8** %8
store i8 %93, i8* %94
br label %95
95: ; preds = %91
%96 = load i8*, i8** %7
%97 = getelementptr inbounds i8, i8* %96, i32 1
store i8* %97, i8** %7
%98 = load i8*, i8** %8
%99 = getelementptr inbounds i8, i8* %98, i32 1
store i8* %99, i8** %8
%100 = load i32, i32* %9
%101 = add nsw i32 %100, -1
store i32 %101, i32* %9
br label %71
102: ; preds = %89
%103 = load i8*, i8** %7
%104 = load i8, i8* %103
%105 = sext i8 %104 to i32
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %125
107: ; preds = %102
%108 = load i8*, i8** %7
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
%111 = icmp ne i32 %110, 10
br i1 %111, label %112, label %125
112: ; preds = %107
%113 = load i8*, i8** %7
%114 = load i8, i8* %113
%115 = sext i8 %114 to i32
%116 = icmp ne i32 %115, 13
br i1 %116, label %117, label %125
117: ; preds = %112
%118 = load i8*, i8** %8
store i8 0, i8* %118
%119 = load i8*, i8** %8
%120 = getelementptr inbounds i8, i8* %119, i32 -1
store i8* %120, i8** %8
store i8 46, i8* %120
%121 = load i8*, i8** %8
%122 = getelementptr inbounds i8, i8* %121, i32 -1
store i8* %122, i8** %8
store i8 46, i8* %122
%123 = load i8*, i8** %8
%124 = getelementptr inbounds i8, i8* %123, i32 -1
store i8* %124, i8** %8
store i8 46, i8* %124
br label %127
125: ; preds = %112, %107, %102
%126 = load i8*, i8** %8
store i8 0, i8* %126
br label %127
127: ; preds = %125, %117
%128 = load i8*, i8** %10
%129 = load i8*, i8** %5
%130 = call i32 @base64_encode_str(i8* %128, i8* %129)
%131 = load i8*, i8** %5
%132 = call i32 @strlen(i8* %131)
ret i32 %132
}

LLVM IR (-O2):
@.str = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/stden/ejudge/refs/heads/master/misctext.c\00"
@.str.1 = [21 x i8] c"assertion failed: %s\00"
@.str.2 = [4 x i8] c"buf\00"
@.str.3 = [9 x i8] c"subject:\00"
@.str.4 = [4 x i8] c"re:\00"
@.str.5 = [13 x i8] c"(no subject)\00"
define i32 @message_base64_subj(i8* nocapture %0, i8* %1, i32 %2) {
%4 = add nsw i32 %2, 4
%5 = tail call i8* @alloca(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @swerr(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i32 414, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %0, i64 8
br label %14
14: ; preds = %19, %12
%15 = phi i8* [ %13, %12 ], [ %20, %19 ]
%16 = load i8, i8* %15
switch i8 %16, label %21 [
i8 32, label %17
i8 9, label %17
]
17: ; preds = %14, %14
%18 = getelementptr inbounds i8, i8* %15, i64 1
br label %19
19: ; preds = %17, %21
%20 = phi i8* [ %18, %17 ], [ %24, %21 ]
br label %14
21: ; preds = %14
%22 = tail call i64 @strncasecmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%23 = icmp eq i64 %22, 0
%24 = getelementptr inbounds i8, i8* %15, i64 3
br i1 %23, label %19, label %25
25: ; preds = %21
switch i8 %16, label %27 [
i8 10, label %26
i8 13, label %26
i8 0, label %26
]
26: ; preds = %25, %25, %25
br label %27
27: ; preds = %9, %25, %26
%28 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), %26 ], [ %15, %25 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), %9 ]
br label %29
29: ; preds = %27, %38
%30 = phi i8* [ %40, %38 ], [ %5, %27 ]
%31 = phi i32 [ %41, %38 ], [ %2, %27 ]
%32 = phi i8* [ %39, %38 ], [ %28, %27 ]
%33 = load i8, i8* %32
switch i8 %33, label %34 [
i8 0, label %47
i8 10, label %47
]
34: ; preds = %29
%35 = icmp ne i8 %33, 13
%36 = icmp ne i32 %31, 0
%37 = select i1 %35, i1 %36, i1 false
br i1 %37, label %38, label %42
38: ; preds = %34
store i8 %33, i8* %30
%39 = getelementptr inbounds i8, i8* %32, i64 1
%40 = getelementptr inbounds i8, i8* %30, i64 1
%41 = add nsw i32 %31, -1
br label %29
42: ; preds = %34
switch i8 %33, label %43 [
i8 0, label %47
i8 13, label %47
]
43: ; preds = %42
store i8 0, i8* %30
%44 = getelementptr inbounds i8, i8* %30, i64 -1
store i8 46, i8* %44
%45 = getelementptr inbounds i8, i8* %30, i64 -2
store i8 46, i8* %45
%46 = getelementptr inbounds i8, i8* %30, i64 -3
store i8 46, i8* %46
br label %48
47: ; preds = %29, %29, %42, %42
store i8 0, i8* %30
br label %48
48: ; preds = %47, %43
%49 = tail call i32 @base64_encode_str(i8* %5, i8* %1)
%50 = tail call i32 @strlen(i8* %1)
ret i32 %50
}