#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 atoi(char *);
int /*<<< orphan*/ clear_line(char *, int);
scalar_t__ isdigit(char);
int conv_line(char *p) {
  int i = 0;
  char line[1000];
  char c = 0;
  clear_line(line, 1000);
  while (isdigit(c = *(p + i)) && c != '\0' && c != '\n') {
    line[i] = c;
    i++;
  }
  return (atoi(line));
}


x86 assembly (clang, -O0):
<conv_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0x401(%rbp)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <clear_line@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x401(%rbp)
movsbl %al,%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x402(%rbp)
je     11b7 <conv_line+0x87>
movsbl -0x401(%rbp),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x402(%rbp)
je     11b7 <conv_line+0x87>
movsbl -0x401(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x402(%rbp)
mov    -0x402(%rbp),%al
test   $0x1,%al
jne    11ca <conv_line+0x9a>
jmp    11e9 <conv_line+0xb9>
mov    -0x401(%rbp),%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x400(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    115e <conv_line+0x2e>
lea    -0x400(%rbp),%rdi
call   1050 <atoi@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conv_line>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1040 <clear_line@plt>
mov    (%r14),%bpl
movsbl %bpl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1197 <conv_line+0x67>
test   %bpl,%bpl
je     1197 <conv_line+0x67>
cmp    $0xa,%bpl
je     1197 <conv_line+0x67>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %bpl,(%rsp,%rbx,1)
movzbl 0x1(%r14,%rbx,1),%ebp
movsbl %bpl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1197 <conv_line+0x67>
cmp    $0xa,%bpl
je     1197 <conv_line+0x67>
add    $0x1,%rbx
test   %bpl,%bpl
jne    1170 <conv_line+0x40>
mov    %rsp,%rdi
call   1050 <atoi@plt>
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @conv_line(i8* nocapture %0) {
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%4 = call i32 @clear_line(i8* %3, i32 1000)
%5 = load i8, i8* %0
%6 = call i64 @isdigit(i8 signext %5)
%7 = freeze i64 %6
%8 = icmp eq i64 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %1
switch i8 %5, label %10 [
i8 10, label %21
i8 0, label %21
]
10: ; preds = %9, %20
%11 = phi i64 [ %14, %20 ], [ 0, %9 ]
%12 = phi i8 [ %16, %20 ], [ %5, %9 ]
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %11
store i8 %12, i8* %13
%14 = add nuw nsw i64 %11, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = call i64 @isdigit(i8 signext %16)
%18 = freeze i64 %17
%19 = icmp eq i64 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %10
switch i8 %16, label %10 [
i8 10, label %21
i8 0, label %21
]
21: ; preds = %10, %20, %20, %9, %9, %1
%22 = call i32 @atoi(i8* %3)
ret i32 %22
}