#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 stream {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
char *stream_getln(struct stream *, size_t *);
int stream_write(struct stream *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int updater_read_checkout(struct stream *src, struct stream *dest) {
  ssize_t nbytes;
  size_t size;
  char *line;
  int first;
  first = 1;
  line = stream_getln(src, &size);
  while (line != NULL) {
    if (line[size - 1] == '\n')
      size--;
    if ((size == 1 && *line == '.') ||
        (size == 2 && strncmp(line, ".+", 2) == 0))
      break;
    if (size >= 2 && strncmp(line, "..", 2) == 0) {
      size--;
      line++;
    }
    if (!first) {
      nbytes = stream_write(dest, "\n", 1);
      if (nbytes == -1)
        return ((-2));
    }
    nbytes = stream_write(dest, line, size);
    if (nbytes == -1)
      return ((-2));
    line = stream_getln(src, &size);
    first = 0;
  }
  if (line == NULL)
    return ((-3));
  if (size == 1 && *line == '.') {
    nbytes = stream_write(dest, "\n", 1);
    if (nbytes == -1)
      return ((-2));
  }
  return (0);
}


x86 assembly (clang, -O0):
<updater_read_checkout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <stream_getln@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     129a <updater_read_checkout+0x16a>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1188 <updater_read_checkout+0x58>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x28(%rbp)
jne    11a3 <updater_read_checkout+0x73>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11cd <updater_read_checkout+0x9d>
cmpq   $0x2,-0x28(%rbp)
jne    11d2 <updater_read_checkout+0xa2>
mov    -0x30(%rbp),%rdi
lea    0xe47(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11d2 <updater_read_checkout+0xa2>
jmp    129a <updater_read_checkout+0x16a>
cmpq   $0x2,-0x28(%rbp)
jb     1214 <updater_read_checkout+0xe4>
mov    -0x30(%rbp),%rdi
lea    0xe1b(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1214 <updater_read_checkout+0xe4>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1251 <updater_read_checkout+0x121>
mov    -0x18(%rbp),%rdi
lea    0xddd(%rip),%rsi
mov    $0x1,%edx
call   1050 <stream_write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    124c <updater_read_checkout+0x11c>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1306 <updater_read_checkout+0x1d6>
jmp    1251 <updater_read_checkout+0x121>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
call   1050 <stream_write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    127d <updater_read_checkout+0x14d>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1306 <updater_read_checkout+0x1d6>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <stream_getln@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
jmp    1158 <updater_read_checkout+0x28>
cmpq   $0x0,-0x30(%rbp)
jne    12b1 <updater_read_checkout+0x181>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1306 <updater_read_checkout+0x1d6>
cmpq   $0x1,-0x28(%rbp)
jne    12ff <updater_read_checkout+0x1cf>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12ff <updater_read_checkout+0x1cf>
mov    -0x18(%rbp),%rdi
lea    0xd2f(%rip),%rsi
mov    $0x1,%edx
call   1050 <stream_write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12fa <updater_read_checkout+0x1ca>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1306 <updater_read_checkout+0x1d6>
jmp    12ff <updater_read_checkout+0x1cf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updater_read_checkout>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsp,%rsi
call   1040 <stream_getln@plt>
mov    $0xfffffffd,%r14d
test   %rax,%rax
je     126b <updater_read_checkout+0x13b>
mov    %rax,%rbp
xor    %r12d,%r12d
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rcx
cmpb   $0xa,-0x1(%rbp,%rcx,1)
jne    1183 <updater_read_checkout+0x53>
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rsp)
cmp    $0x2,%rcx
je     11a0 <updater_read_checkout+0x70>
cmp    $0x1,%rcx
jne    11bd <updater_read_checkout+0x8d>
cmpb   $0x2e,0x0(%rbp)
jne    11dc <updater_read_checkout+0xac>
jmp    1247 <updater_read_checkout+0x117>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0xe56(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    (%rsp),%rcx
test   %rax,%rax
je     123b <updater_read_checkout+0x10b>
cmp    $0x2,%rcx
jb     11dc <updater_read_checkout+0xac>
mov    %rbp,%rdi
lea    0xe36(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     122a <updater_read_checkout+0xfa>
test   $0x1,%r12b
je     11fb <updater_read_checkout+0xcb>
mov    %rbx,%rdi
lea    0xe1a(%rip),%rsi
mov    $0x1,%edx
call   1050 <stream_write@plt>
cmp    $0xffffffff,%eax
je     1265 <updater_read_checkout+0x135>
mov    (%rsp),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <stream_write@plt>
cmp    $0xffffffff,%eax
je     1265 <updater_read_checkout+0x135>
mov    %r15,%rdi
mov    %r13,%rsi
call   1040 <stream_getln@plt>
mov    %rax,%rbp
mov    $0x1,%r12b
test   %rax,%rax
jne    1170 <updater_read_checkout+0x40>
jmp    126b <updater_read_checkout+0x13b>
addq   $0xffffffffffffffff,(%rsp)
add    $0x1,%rbp
test   $0x1,%r12b
jne    11e2 <updater_read_checkout+0xb2>
jmp    11fb <updater_read_checkout+0xcb>
cmp    $0x1,%rcx
jne    1260 <updater_read_checkout+0x130>
cmpb   $0x2e,0x0(%rbp)
jne    1260 <updater_read_checkout+0x130>
lea    0xdb8(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <stream_write@plt>
cmp    $0xffffffff,%eax
je     1265 <updater_read_checkout+0x135>
xor    %r14d,%r14d
jmp    126b <updater_read_checkout+0x13b>
mov    $0xfffffffe,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stream = type { i32 }
@.str = [3 x i8] c".+\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @updater_read_checkout(%struct.stream* %0, %struct.stream* %1) {
%3 = alloca i32
%4 = alloca %struct.stream*
%5 = alloca %struct.stream*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store %struct.stream* %0, %struct.stream** %4
store %struct.stream* %1, %struct.stream** %5
store i32 1, i32* %9
%10 = load %struct.stream*, %struct.stream** %4
%11 = call i8* @stream_getln(%struct.stream* %10, i64* %7)
store i8* %11, i8** %8
br label %12
12: ; preds = %73, %2
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %76
15: ; preds = %12
%16 = load i8*, i8** %8
%17 = load i64, i64* %7
%18 = sub i64 %17, 1
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %26
23: ; preds = %15
%24 = load i64, i64* %7
%25 = add i64 %24, -1
store i64 %25, i64* %7
br label %26
26: ; preds = %23, %15
%27 = load i64, i64* %7
%28 = icmp eq i64 %27, 1
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i8*, i8** %8
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 46
br i1 %33, label %41, label %34
34: ; preds = %29, %26
%35 = load i64, i64* %7
%36 = icmp eq i64 %35, 2
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i8*, i8** %8
%39 = call i64 @strncmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37, %29
br label %76
42: ; preds = %37, %34
%43 = load i64, i64* %7
%44 = icmp uge i64 %43, 2
br i1 %44, label %45, label %54
45: ; preds = %42
%46 = load i8*, i8** %8
%47 = call i64 @strncmp(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = load i64, i64* %7
%51 = add i64 %50, -1
store i64 %51, i64* %7
%52 = load i8*, i8** %8
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %8
br label %54
54: ; preds = %49, %45, %42
%55 = load i32, i32* %9
%56 = icmp ne i32 %55, 0
br i1 %56, label %64, label %57
57: ; preds = %54
%58 = load %struct.stream*, %struct.stream** %5
%59 = call i32 @stream_write(%struct.stream* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i32 %59, i32* %6
%60 = load i32, i32* %6
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %63
62: ; preds = %57
store i32 -2, i32* %3
br label %96
63: ; preds = %57
br label %64
64: ; preds = %63, %54
%65 = load %struct.stream*, %struct.stream** %5
%66 = load i8*, i8** %8
%67 = load i64, i64* %7
%68 = trunc i64 %67 to i32
%69 = call i32 @stream_write(%struct.stream* %65, i8* %66, i32 %68)
store i32 %69, i32* %6
%70 = load i32, i32* %6
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %73
72: ; preds = %64
store i32 -2, i32* %3
br label %96
73: ; preds = %64
%74 = load %struct.stream*, %struct.stream** %4
%75 = call i8* @stream_getln(%struct.stream* %74, i64* %7)
store i8* %75, i8** %8
store i32 0, i32* %9
br label %12
76: ; preds = %41, %12
%77 = load i8*, i8** %8
%78 = icmp eq i8* %77, null
br i1 %78, label %79, label %80
79: ; preds = %76
store i32 -3, i32* %3
br label %96
80: ; preds = %76
%81 = load i64, i64* %7
%82 = icmp eq i64 %81, 1
br i1 %82, label %83, label %95
83: ; preds = %80
%84 = load i8*, i8** %8
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 %86, 46
br i1 %87, label %88, label %95
88: ; preds = %83
%89 = load %struct.stream*, %struct.stream** %5
%90 = call i32 @stream_write(%struct.stream* %89, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
store i32 %90, i32* %6
%91 = load i32, i32* %6
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %94
93: ; preds = %88
store i32 -2, i32* %3
br label %96
94: ; preds = %88
br label %95
95: ; preds = %94, %83, %80
store i32 0, i32* %3
br label %96
96: ; preds = %95, %93, %79, %72, %62
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
%struct.stream = type { i32 }
@.str = [3 x i8] c".+\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @updater_read_checkout(%struct.stream* %0, %struct.stream* %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i8* @stream_getln(%struct.stream* %0, i64* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %57, label %7
7: ; preds = %2, %45
%8 = phi i1 [ true, %45 ], [ false, %2 ]
%9 = phi i8* [ %46, %45 ], [ %5, %2 ]
%10 = load i64, i64* %3
%11 = add i64 %10, -1
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %7
store i64 %11, i64* %3
br label %16
16: ; preds = %15, %7
%17 = phi i64 [ %11, %15 ], [ %10, %7 ]
switch i64 %17, label %25 [
i64 1, label %18
i64 2, label %21
]
18: ; preds = %16
%19 = load i8, i8* %9
%20 = icmp eq i8 %19, 46
br i1 %20, label %53, label %35
21: ; preds = %16
%22 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%23 = icmp eq i64 %22, 0
%24 = load i64, i64* %3
br i1 %23, label %48, label %25
25: ; preds = %21, %16
%26 = phi i64 [ %17, %16 ], [ %24, %21 ]
%27 = icmp ugt i64 %26, 1
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = call i64 @strncmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i64, i64* %3
%33 = add i64 %32, -1
store i64 %33, i64* %3
%34 = getelementptr inbounds i8, i8* %9, i64 1
br label %35
35: ; preds = %18, %31, %28, %25
%36 = phi i8* [ %34, %31 ], [ %9, %28 ], [ %9, %25 ], [ %9, %18 ]
br i1 %8, label %37, label %40
37: ; preds = %35
%38 = call i32 @stream_write(%struct.stream* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%39 = icmp eq i32 %38, -1
br i1 %39, label %57, label %40
40: ; preds = %37, %35
%41 = load i64, i64* %3
%42 = trunc i64 %41 to i32
%43 = call i32 @stream_write(%struct.stream* %1, i8* %36, i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %57, label %45
45: ; preds = %40
%46 = call i8* @stream_getln(%struct.stream* %0, i64* %3)
%47 = icmp eq i8* %46, null
br i1 %47, label %57, label %7
48: ; preds = %21
%49 = icmp eq i64 %24, 1
br i1 %49, label %50, label %56
50: ; preds = %48
%51 = load i8, i8* %9
%52 = icmp eq i8 %51, 46
br i1 %52, label %53, label %56
53: ; preds = %18, %50
%54 = call i32 @stream_write(%struct.stream* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%55 = icmp eq i32 %54, -1
br i1 %55, label %57, label %56
56: ; preds = %53, %50, %48
br label %57
57: ; preds = %37, %40, %45, %2, %53, %56
%58 = phi i32 [ 0, %56 ], [ -2, %53 ], [ -3, %2 ], [ -2, %37 ], [ -2, %40 ], [ -3, %45 ]
ret i32 %58
}