#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 */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int readField(int, char **, char);
int sendRequest(int, char *, char *, int);
scalar_t__ strcmpi(char *, char *);
int readf(int sd, char argv[]) {
  int status = sendRequest(sd, "READ", argv, 1);
  if (status > 0) {
    char *from = NULL;
    char *subject = NULL;
    char *text = NULL;
    if ((status = readField(sd, &text, ':')) > 0 && strcmpi("OK", text) == 0) {
      free(text);
      if ((status = readField(sd, &from, ':')) > 0 &&
          (status = readField(sd, &subject, ':')) > 0 &&
          (status = readField(sd, &text, ':')) > 0) {
        printf("\nFROM   : %s\n", from);
        printf("SUBJECT: %s\n", subject);
        printf("\n%s\n\n", text);
        free(from);
        free(subject);
        free(text);
      }
    } else {
      free(text);
      if ((status = readField(sd, &text, ':')) > 0) {
        printf("-%s\n", text);
      }
      free(text);
    }
    if (status < 0)
      status = -3;
  }
  return status;
}


x86 assembly (clang, -O0):
<readf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    0xe93(%rip),%rsi
mov    $0x1,%ecx
call   1070 <sendRequest@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    12d8 <readf+0x188>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x3a,%edx
call   1050 <readField@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1283 <readf+0x133>
mov    -0x30(%rbp),%rsi
lea    0xe41(%rip),%rdi
call   1060 <strcmpi@plt>
cmp    $0x0,%rax
jne    1283 <readf+0x133>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x3a,%edx
call   1050 <readField@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    127e <readf+0x12e>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x3a,%edx
call   1050 <readField@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    127e <readf+0x12e>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x3a,%edx
call   1050 <readField@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    127e <readf+0x12e>
mov    -0x20(%rbp),%rsi
lea    0xdca(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xdc8(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xdc5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    12c2 <readf+0x172>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x3a,%edx
call   1050 <readField@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    12b9 <readf+0x169>
mov    -0x30(%rbp),%rsi
lea    0xd75(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x14(%rbp)
jge    12d3 <readf+0x183>
movl   $0xfffffffd,-0x14(%rbp)
jmp    12d8 <readf+0x188>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readf>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rdx
mov    %edi,%ebp
lea    0xe9e(%rip),%rsi
mov    $0x1,%ecx
call   1070 <sendRequest@plt>
test   %eax,%eax
jle    11f7 <readf+0xa7>
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x3a,%edx
call   1050 <readField@plt>
test   %eax,%eax
jle    11b6 <readf+0x66>
mov    (%rsp),%rsi
lea    0xe59(%rip),%rdi
call   1060 <strcmpi@plt>
test   %rax,%rax
je     11fe <readf+0xae>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x3a,%edx
call   1050 <readField@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    11e4 <readf+0x94>
mov    (%rsp),%rsi
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
test   %ebx,%ebx
mov    $0xfffffffd,%eax
cmovns %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    (%rsp),%rdi
call   1030 <free@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3a,%edx
call   1050 <readField@plt>
test   %eax,%eax
jle    1291 <readf+0x141>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3a,%edx
call   1050 <readField@plt>
test   %eax,%eax
jle    1291 <readf+0x141>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x3a,%edx
call   1050 <readField@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    11ed <readf+0x9d>
mov    0x10(%rsp),%rsi
lea    0xdb6(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%rsi
lea    0xdb3(%rip),%rdi
call   1040 <printf@plt>
mov    (%rsp),%rsi
lea    0xdb0(%rip),%rdi
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    11e4 <readf+0x94>
mov    %eax,%ebx
jmp    11ed <readf+0x9d>

LLVM IR (-O0):
@.str = [5 x i8] c"READ\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [14 x i8] c"\0AFROM : %s\0A\00"
@.str.3 = [13 x i8] c"SUBJECT: %s\0A\00"
@.str.4 = [6 x i8] c"\0A%s\0A\0A\00"
@.str.5 = [5 x i8] c"-%s\0A\00"
define i32 @readf(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = load i32, i32* %3
%10 = load i8*, i8** %4
%11 = call i32 @sendRequest(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %10, i32 1)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %67
14: ; preds = %2
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
%15 = load i32, i32* %3
%16 = call i32 @readField(i32 %15, i8** %8, i8 signext 58)
store i32 %16, i32* %5
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %50
18: ; preds = %14
%19 = load i8*, i8** %8
%20 = call i64 @strcmpi(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %50
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = call i32 @free(i8* %23)
%25 = load i32, i32* %3
%26 = call i32 @readField(i32 %25, i8** %6, i8 signext 58)
store i32 %26, i32* %5
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %49
28: ; preds = %22
%29 = load i32, i32* %3
%30 = call i32 @readField(i32 %29, i8** %7, i8 signext 58)
store i32 %30, i32* %5
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %49
32: ; preds = %28
%33 = load i32, i32* %3
%34 = call i32 @readField(i32 %33, i8** %8, i8 signext 58)
store i32 %34, i32* %5
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %49
36: ; preds = %32
%37 = load i8*, i8** %6
%38 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = load i8*, i8** %7
%40 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %8
%42 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = load i8*, i8** %6
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
%47 = load i8*, i8** %8
%48 = call i32 @free(i8* %47)
br label %49
49: ; preds = %36, %32, %28, %22
br label %62
50: ; preds = %18, %14
%51 = load i8*, i8** %8
%52 = call i32 @free(i8* %51)
%53 = load i32, i32* %3
%54 = call i32 @readField(i32 %53, i8** %8, i8 signext 58)
store i32 %54, i32* %5
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %50
%57 = load i8*, i8** %8
%58 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %56, %50
%60 = load i8*, i8** %8
%61 = call i32 @free(i8* %60)
br label %62
62: ; preds = %59, %49
%63 = load i32, i32* %5
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %62
store i32 -3, i32* %5
br label %66
66: ; preds = %65, %62
br label %67
67: ; preds = %66, %2
%68 = load i32, i32* %5
ret i32 %68
}

LLVM IR (-O2):
@.str = [5 x i8] c"READ\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [14 x i8] c"\0AFROM : %s\0A\00"
@.str.3 = [13 x i8] c"SUBJECT: %s\0A\00"
@.str.4 = [6 x i8] c"\0A%s\0A\0A\00"
@.str.5 = [5 x i8] c"-%s\0A\00"
define i32 @readf(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = tail call i32 @sendRequest(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1, i32 1)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %56
8: ; preds = %2
%9 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%10 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%11 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%12 = call i32 @readField(i32 %0, i8** %5, i8 signext 58)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %40
14: ; preds = %8
%15 = load i8*, i8** %5
%16 = call i64 @strcmpi(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %40
18: ; preds = %14
%19 = load i8*, i8** %5
%20 = call i32 @free(i8* %19)
%21 = call i32 @readField(i32 %0, i8** %3, i8 signext 58)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %52
23: ; preds = %18
%24 = call i32 @readField(i32 %0, i8** %4, i8 signext 58)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %52
26: ; preds = %23
%27 = call i32 @readField(i32 %0, i8** %5, i8 signext 58)
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %52
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %4
%33 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %5
%35 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %3
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %4
%39 = call i32 @free(i8* %38)
br label %48
40: ; preds = %14, %8
%41 = load i8*, i8** %5
%42 = call i32 @free(i8* %41)
%43 = call i32 @readField(i32 %0, i8** %5, i8 signext 58)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i8*, i8** %5
%47 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %40, %45, %29
%49 = phi i32 [ %27, %29 ], [ %43, %45 ], [ %43, %40 ]
%50 = load i8*, i8** %5
%51 = call i32 @free(i8* %50)
br label %52
52: ; preds = %48, %18, %23, %26
%53 = phi i32 [ %27, %26 ], [ %24, %23 ], [ %21, %18 ], [ %49, %48 ]
%54 = icmp slt i32 %53, 0
%55 = select i1 %54, i32 -3, i32 %53
br label %56
56: ; preds = %52, %2
%57 = phi i32 [ %55, %52 ], [ %6, %2 ]
ret i32 %57
}