#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 */
char EOF;
char *_DC_message_name(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *realloc(char *, int);
int /*<<< orphan*/ unlink(char *);
char *_DC_read_message(char *box, char *name, int del_msg) {
  FILE *f;
  char *fn = _DC_message_name(box, name);
  char *buf = NULL;
  if (fn == NULL)
    return (NULL);
  if ((f = fopen(fn, "r")) != NULL) {
    int bs = 100, i;
    char c;
    buf = malloc(bs);
    i = 0;
    buf[i] = '\0';
    while ((c = fgetc(f)) != EOF) {
      if (i > bs - 2) {
        bs += 100;
        buf = realloc(buf, bs);
      }
      buf[i] = c;
      i++;
      buf[i] = '\0';
    }
    fclose(f);
    if (del_msg)
      unlink(fn);
  }
  if (fn != NULL)
    free(fn);
  return (buf);
}


x86 assembly (clang, -O0):
<_DC_read_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <_DC_message_name@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c4 <_DC_read_message+0x44>
movq   $0x0,-0x8(%rbp)
jmp    12b8 <_DC_read_message+0x138>
mov    -0x30(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     129c <_DC_read_message+0x11c>
movl   $0x64,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x41(%rbp)
movsbl %al,%eax
mov    0x2dca(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     127b <_DC_read_message+0xfb>
mov    -0x40(%rbp),%eax
mov    -0x3c(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jle    1253 <_DC_read_message+0xd3>
mov    -0x3c(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%esi
call   1090 <realloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x41(%rbp),%dl
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x40(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1208 <_DC_read_message+0x88>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1297 <_DC_read_message+0x117>
mov    -0x30(%rbp),%rdi
call   1040 <unlink@plt>
jmp    129c <_DC_read_message+0x11c>
cmpq   $0x0,-0x30(%rbp)
je     12b0 <_DC_read_message+0x130>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_DC_read_message>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
call   1070 <_DC_message_name@plt>
test   %rax,%rax
je     1205 <_DC_read_message+0x85>
mov    %rax,%r15
lea    0xe5c(%rip),%rsi
mov    %rax,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1209 <_DC_read_message+0x89>
mov    %rax,%r12
mov    %ebx,0xc(%rsp)
mov    $0x64,%r13d
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %r12,%rdi
call   1060 <fgetc@plt>
mov    0x2e0b(%rip),%r14
cmp    (%r14),%al
mov    %r15,0x10(%rsp)
jne    120d <_DC_read_message+0x8d>
mov    %r12,%rdi
call   1050 <fclose@plt>
cmpl   $0x0,0xc(%rsp)
je     125d <_DC_read_message+0xdd>
mov    0x10(%rsp),%r15
mov    %r15,%rdi
call   1040 <unlink@plt>
jmp    1262 <_DC_read_message+0xe2>
xor    %ebp,%ebp
jmp    126a <_DC_read_message+0xea>
xor    %ebp,%ebp
jmp    1262 <_DC_read_message+0xe2>
mov    %eax,%ebx
xor    %r15d,%r15d
jmp    123e <_DC_read_message+0xbe>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %bl,0x0(%rbp,%r15,1)
movb   $0x0,0x1(%rbp,%r15,1)
add    $0x1,%r15
mov    %r12,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebx
cmp    (%r14),%al
je     11e7 <_DC_read_message+0x67>
lea    -0x2(%r13),%eax
cltq
cmp    %rax,%r15
jle    1220 <_DC_read_message+0xa0>
add    $0x64,%r13d
mov    %rbp,%rdi
mov    %r13d,%esi
call   1090 <realloc@plt>
mov    %rax,%rbp
jmp    1220 <_DC_read_message+0xa0>
mov    0x10(%rsp),%r15
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i8* @_DC_read_message(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = call i8* @_DC_message_name(i8* %14, i8* %15)
store i8* %16, i8** %9
store i8* null, i8** %10
%17 = load i8*, i8** %9
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %3
store i8* null, i8** %4
br label %78
20: ; preds = %3
%21 = load i8*, i8** %9
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %8
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %70
24: ; preds = %20
store i32 100, i32* %11
%25 = load i32, i32* %11
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %10
store i32 0, i32* %12
%27 = load i8*, i8** %10
%28 = load i32, i32* %12
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %49, %24
%32 = load i32*, i32** %8
%33 = call signext i8 @fgetc(i32* %32)
store i8 %33, i8* %13
%34 = sext i8 %33 to i32
%35 = load i8, i8* @EOF
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %34, %36
br i1 %37, label %38, label %61
38: ; preds = %31
%39 = load i32, i32* %12
%40 = load i32, i32* %11
%41 = sub nsw i32 %40, 2
%42 = icmp sgt i32 %39, %41
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i32, i32* %11
%45 = add nsw i32 %44, 100
store i32 %45, i32* %11
%46 = load i8*, i8** %10
%47 = load i32, i32* %11
%48 = call i8* @realloc(i8* %46, i32 %47)
store i8* %48, i8** %10
br label %49
49: ; preds = %43, %38
%50 = load i8, i8* %13
%51 = load i8*, i8** %10
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 %50, i8* %54
%55 = load i32, i32* %12
%56 = add nsw i32 %55, 1
store i32 %56, i32* %12
%57 = load i8*, i8** %10
%58 = load i32, i32* %12
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 0, i8* %60
br label %31
61: ; preds = %31
%62 = load i32*, i32** %8
%63 = call i32 @fclose(i32* %62)
%64 = load i32, i32* %7
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %61
%67 = load i8*, i8** %9
%68 = call i32 @unlink(i8* %67)
br label %69
69: ; preds = %66, %61
br label %70
70: ; preds = %69, %20
%71 = load i8*, i8** %9
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %76
73: ; preds = %70
%74 = load i8*, i8** %9
%75 = call i32 @free(i8* %74)
br label %76
76: ; preds = %73, %70
%77 = load i8*, i8** %10
store i8* %77, i8** %4
br label %78
78: ; preds = %76, %19
%79 = load i8*, i8** %4
ret i8* %79
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i8* @_DC_read_message(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @_DC_message_name(i8* %0, i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %43, label %6
6: ; preds = %3
%7 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %40, label %9
9: ; preds = %6
%10 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
store i8 0, i8* %10
%11 = tail call signext i8 @fgetc(i32* %7)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
br i1 %13, label %34, label %14
14: ; preds = %9, %25
%15 = phi i64 [ %29, %25 ], [ 0, %9 ]
%16 = phi i8 [ %31, %25 ], [ %11, %9 ]
%17 = phi i32 [ %27, %25 ], [ 100, %9 ]
%18 = phi i8* [ %26, %25 ], [ %10, %9 ]
%19 = add nsw i32 %17, -2
%20 = sext i32 %19 to i64
%21 = icmp sgt i64 %15, %20
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = add nsw i32 %17, 100
%24 = tail call i8* @realloc(i8* %18, i32 %23)
br label %25
25: ; preds = %22, %14
%26 = phi i8* [ %24, %22 ], [ %18, %14 ]
%27 = phi i32 [ %23, %22 ], [ %17, %14 ]
%28 = getelementptr inbounds i8, i8* %26, i64 %15
store i8 %16, i8* %28
%29 = add nuw i64 %15, 1
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 0, i8* %30
%31 = tail call signext i8 @fgetc(i32* %7)
%32 = load i8, i8* @EOF
%33 = icmp eq i8 %31, %32
br i1 %33, label %34, label %14
34: ; preds = %25, %9
%35 = phi i8* [ %10, %9 ], [ %26, %25 ]
%36 = tail call i32 @fclose(i32* %7)
%37 = icmp eq i32 %2, 0
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = tail call i32 @unlink(i8* %4)
br label %40
40: ; preds = %6, %38, %34
%41 = phi i8* [ null, %6 ], [ %35, %38 ], [ %35, %34 ]
%42 = tail call i32 @free(i8* %4)
br label %43
43: ; preds = %3, %40
%44 = phi i8* [ %41, %40 ], [ null, %3 ]
ret i8* %44
}