#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 */
struct message {
  int dummy;
};
struct mansession {
  int dummy;
};

/* Variables and functions */
int ParseXMLInput(char *, struct message *);
int /*<<< orphan*/ debugmsg(char *, char *);
int get_input(struct mansession *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ proxyerror_do(struct mansession *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int _read(struct mansession *s, struct message *m) {
  char line[1024], xmlbuf[1024];
  int res;
  memset(xmlbuf, 0, sizeof xmlbuf);
  for (;;) {
    memset(line, 0, sizeof line);
    res = get_input(s, line);
    if (res > 0) {
      if (*line == '\0') {
        break;
      } else if (strlen(xmlbuf) < (1024 - strlen(line)))
        strcat(xmlbuf, line);
    } else if (res < 0)
      return res;
  }
  debugmsg("Got xml: %s", xmlbuf);
  res = ParseXMLInput(xmlbuf, m);
  if (res < 0)
    proxyerror_do(s, "Invalid XML Input");
  return res;
}


x86 assembly (clang, -O0):
<_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1090 <get_input@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0x0,-0x824(%rbp)
jle    1233 <_read+0xc3>
movsbl -0x420(%rbp),%eax
cmp    $0x0,%eax
jne    11e1 <_read+0x71>
jmp    1258 <_read+0xe8>
lea    -0x820(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x828(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edx
mov    -0x828(%rbp),%eax
mov    $0x400,%ecx
sub    %edx,%ecx
cmp    %ecx,%eax
jge    1229 <_read+0xb9>
lea    -0x820(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1080 <strcat@plt>
jmp    122e <_read+0xbe>
jmp    1253 <_read+0xe3>
cmpl   $0x0,-0x824(%rbp)
jge    124e <_read+0xde>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a7 <_read+0x137>
jmp    1253 <_read+0xe3>
jmp    1196 <_read+0x26>
lea    -0x820(%rbp),%rsi
lea    0xd9a(%rip),%rdi
call   1040 <debugmsg@plt>
lea    -0x820(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <ParseXMLInput@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0x0,-0x824(%rbp)
jge    129e <_read+0x12e>
mov    -0x10(%rbp),%rdi
lea    0xd73(%rip),%rsi
call   1030 <proxyerror_do@plt>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_read>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    0x400(%rsp),%rbx
jmp    11b6 <_read+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
js     123c <_read+0xcc>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1090 <get_input@plt>
test   %eax,%eax
jle    11b0 <_read+0x40>
cmpb   $0x0,0x400(%rsp)
je     1208 <_read+0x98>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x400,%ecx
sub    %eax,%ecx
cmp    %ecx,%ebp
jge    11b6 <_read+0x46>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
jmp    11b6 <_read+0x46>
lea    0xdf1(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1040 <debugmsg@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <ParseXMLInput@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    123e <_read+0xce>
lea    0xdda(%rip),%rsi
mov    %r12,%rdi
call   1030 <proxyerror_do@plt>
jmp    123e <_read+0xce>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mansession = type { i32 }
%struct.message = type { i32 }
@.str = [12 x i8] c"Got xml: %s\00"
@.str.1 = [18 x i8] c"Invalid XML Input\00"
define i32 @_read(%struct.mansession* %0, %struct.message* %1) {
%3 = alloca i32
%4 = alloca %struct.mansession*
%5 = alloca %struct.message*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
store %struct.mansession* %0, %struct.mansession** %4
store %struct.message* %1, %struct.message** %5
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 1024)
br label %11
11: ; preds = %44, %2
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 1024)
%14 = load %struct.mansession*, %struct.mansession** %4
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = call i32 @get_input(%struct.mansession* %14, i8* %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %38
19: ; preds = %11
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
br label %45
25: ; preds = %19
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 1024, %29
%31 = icmp slt i32 %27, %30
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%35 = call i32 @strcat(i8* %33, i8* %34)
br label %36
36: ; preds = %32, %25
br label %37
37: ; preds = %36
br label %44
38: ; preds = %11
%39 = load i32, i32* %8
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = load i32, i32* %8
store i32 %42, i32* %3
br label %58
43: ; preds = %38
br label %44
44: ; preds = %43, %37
br label %11
45: ; preds = %24
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%47 = call i32 @debugmsg(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%49 = load %struct.message*, %struct.message** %5
%50 = call i32 @ParseXMLInput(i8* %48, %struct.message* %49)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %45
%54 = load %struct.mansession*, %struct.mansession** %4
%55 = call i32 @proxyerror_do(%struct.mansession* %54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %56
56: ; preds = %53, %45
%57 = load i32, i32* %8
store i32 %57, i32* %3
br label %58
58: ; preds = %56, %41
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.mansession = type { i32 }
%struct.message = type { i32 }
@.str = [12 x i8] c"Got xml: %s\00"
@.str.1 = [18 x i8] c"Invalid XML Input\00"
define i32 @_read(%struct.mansession* %0, %struct.message* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 1024)
br label %8
8: ; preds = %24, %2
%9 = call i32 @memset(i8* %5, i32 0, i32 1024)
%10 = call i32 @get_input(%struct.mansession* %0, i8* %5)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i8, i8* %5
%14 = icmp eq i8 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %12
%16 = call i32 @strlen(i8* %6)
%17 = call i32 @strlen(i8* %5)
%18 = sub nsw i32 1024, %17
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = call i32 @strcat(i8* %6, i8* %5)
br label %24
22: ; preds = %8
%23 = icmp slt i32 %10, 0
br i1 %23, label %31, label %24
24: ; preds = %22, %20, %15
br label %8
25: ; preds = %12
%26 = call i32 @debugmsg(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %6)
%27 = call i32 @ParseXMLInput(i8* %6, %struct.message* %1)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @proxyerror_do(%struct.mansession* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %22, %25, %29
%32 = phi i32 [ %27, %29 ], [ %27, %25 ], [ %10, %22 ]
ret i32 %32
}