#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 congtchr();
int /*<<< orphan*/ conptchr(char);
int congtstr(char *buffer, short size, char term) {
  char *ptrBuffer = 0;
  int count = 0;
  char c = 0;
  ptrBuffer = buffer;
  while (count < size && c != term) {
    c = congtchr();
    (void)conptchr(c);
    if (c != term) {
      *ptrBuffer++ = c;
      count++;
    }
  }
  return count;
}


x86 assembly (clang, -O0):
<congtstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %si,%cx
mov    %rdi,-0x8(%rbp)
mov    %cx,-0xa(%rbp)
mov    %al,-0xb(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
movswl -0xa(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x1e(%rbp)
jge    1177 <congtstr+0x57>
movsbl -0x1d(%rbp),%eax
movsbl -0xb(%rbp),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x1e(%rbp)
mov    -0x1e(%rbp),%al
test   $0x1,%al
jne    1187 <congtstr+0x67>
jmp    11cc <congtstr+0xac>
mov    $0x0,%al
call   1030 <congtchr@plt>
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%edi
call   1040 <conptchr@plt>
movsbl -0x1d(%rbp),%eax
movsbl -0xb(%rbp),%ecx
cmp    %ecx,%eax
je     11c7 <congtstr+0xa7>
mov    -0x1d(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <congtstr+0x33>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<congtstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
xor    %ebp,%ebp
test   %r14w,%r14w
jle    116a <congtstr+0x4a>
mov    %edx,%r12d
test   %r12b,%r12b
je     116a <congtstr+0x4a>
mov    %rdi,%r15
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <congtchr@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1040 <conptchr@plt>
cmp    %r12b,%bl
je     1160 <congtstr+0x40>
mov    %bl,(%r15)
add    $0x1,%r15
add    $0x1,%ebp
cmp    %r14d,%ebp
jge    116a <congtstr+0x4a>
cmp    %r12b,%bl
jne    1140 <congtstr+0x20>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @congtstr(i8* %0, i16 signext %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i16 %1, i16* %5
store i8 %2, i8* %6
store i8* null, i8** %7
store i32 0, i32* %8
store i8 0, i8* %9
%10 = load i8*, i8** %4
store i8* %10, i8** %7
br label %11
11: ; preds = %39, %3
%12 = load i32, i32* %8
%13 = load i16, i16* %5
%14 = sext i16 %13 to i32
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i8, i8* %9
%18 = sext i8 %17 to i32
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %18, %20
br label %22
22: ; preds = %16, %11
%23 = phi i1 [ false, %11 ], [ %21, %16 ]
br i1 %23, label %24, label %40
24: ; preds = %22
%25 = call signext i8 (...) @congtchr()
store i8 %25, i8* %9
%26 = load i8, i8* %9
%27 = call i32 @conptchr(i8 signext %26)
%28 = load i8, i8* %9
%29 = sext i8 %28 to i32
%30 = load i8, i8* %6
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %29, %31
br i1 %32, label %33, label %39
33: ; preds = %24
%34 = load i8, i8* %9
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %7
store i8 %34, i8* %35
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %39
39: ; preds = %33, %24
br label %11
40: ; preds = %22
%41 = load i32, i32* %8
ret i32 %41
}

LLVM IR (-O2):
define i32 @congtstr(i8* nocapture writeonly %0, i16 signext %1, i8 signext %2) {
%4 = sext i16 %1 to i32
%5 = icmp sgt i16 %1, 0
%6 = icmp ne i8 %2, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %23
8: ; preds = %3, %17
%9 = phi i32 [ %19, %17 ], [ 0, %3 ]
%10 = phi i8* [ %18, %17 ], [ %0, %3 ]
%11 = tail call signext i8 (...) @congtchr()
%12 = tail call i32 @conptchr(i8 signext %11)
%13 = icmp eq i8 %11, %2
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %11, i8* %10
%16 = add nsw i32 %9, 1
br label %17
17: ; preds = %14, %8
%18 = phi i8* [ %15, %14 ], [ %10, %8 ]
%19 = phi i32 [ %16, %14 ], [ %9, %8 ]
%20 = icmp slt i32 %19, %4
%21 = icmp ne i8 %11, %2
%22 = and i1 %20, %21
br i1 %22, label %8, label %23
23: ; preds = %17, %3
%24 = phi i32 [ 0, %3 ], [ %19, %17 ]
ret i32 %24
}