#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 EOF;
int getchar();
void read_poly(int *nc, char p[]) {
  int c, i = 0;
  while ((c = getchar()) != EOF && c != ';')
    p[i++] = c;
  p[i++] = ';';
  p[i++] = '\0';
  *nc = i;
}


x86 assembly (clang, -O0):
<read_poly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
mov    0x2eac(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     1151 <read_poly+0x41>
cmpl   $0x3b,-0x14(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1161 <read_poly+0x51>
jmp    1180 <read_poly+0x70>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1127 <read_poly+0x17>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x3b,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_poly>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0x3b,%eax
je     115a <read_poly+0x4a>
mov    0x2eb5(%rip),%r12
cmp    (%r12),%eax
je     115a <read_poly+0x4a>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0x3b,%eax
je     115a <read_poly+0x4a>
cmp    (%r12),%eax
jne    1140 <read_poly+0x30>
mov    %ebx,%eax
movw   $0x3b,(%r15,%rax,1)
add    $0x2,%ebx
mov    %ebx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define void @read_poly(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %6
br label %7
7: ; preds = %16, %2
%8 = call i32 (...) @getchar()
store i32 %8, i32* %5
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 59
br label %14
14: ; preds = %11, %7
%15 = phi i1 [ false, %7 ], [ %13, %11 ]
br i1 %15, label %16, label %24
16: ; preds = %14
%17 = load i32, i32* %5
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %4
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 %18, i8* %23
br label %7
24: ; preds = %14
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 59, i8* %29
%30 = load i8*, i8** %4
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* %6
%36 = load i32*, i32** %3
store i32 %35, i32* %36
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
define void @read_poly(i32* nocapture writeonly %0, i8* nocapture writeonly %1) {
%3 = tail call i32 (...) @getchar()
%4 = load i32, i32* @EOF
%5 = icmp ne i32 %3, %4
%6 = icmp ne i32 %3, 59
%7 = and i1 %6, %5
br i1 %7, label %8, label %21
8: ; preds = %2, %8
%9 = phi i64 [ %12, %8 ], [ 0, %2 ]
%10 = phi i32 [ %14, %8 ], [ %3, %2 ]
%11 = trunc i32 %10 to i8
%12 = add nuw i64 %9, 1
%13 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %11, i8* %13
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
%17 = icmp ne i32 %14, 59
%18 = and i1 %17, %16
br i1 %18, label %8, label %19
19: ; preds = %8
%20 = trunc i64 %12 to i32
br label %21
21: ; preds = %19, %2
%22 = phi i32 [ 0, %2 ], [ %20, %19 ]
%23 = add nuw nsw i32 %22, 1
%24 = zext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 59, i8* %25
%26 = add nuw nsw i32 %22, 2
%27 = zext i32 %23 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
store i8 0, i8* %28
store i32 %26, i32* %0
ret void
}