#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 */
typedef int /*<<< orphan*/ n;

/* Variables and functions */
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int readnum(char n[]) {
  int i;
  memset(n, 0, sizeof(n));
  gets(n);
  for (i = 0; n[i] && n[i] != '\n';)
    i++;
  return i;
}


x86 assembly (clang, -O0):
<readnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1040 <gets@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
je     117b <readnum+0x5b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    118b <readnum+0x6b>
jmp    1199 <readnum+0x79>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114c <readnum+0x2c>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readnum>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    %r14,%rdi
call   1040 <gets@plt>
nopl   (%rax)
movzbl (%r14,%rbx,1),%eax
test   %al,%al
je     1153 <readnum+0x33>
cmp    $0xa,%al
je     1153 <readnum+0x33>
add    $0x1,%rbx
jmp    1140 <readnum+0x20>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @readnum(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @memset(i8* %4, i32 0, i32 8)
%6 = load i8*, i8** %2
%7 = call i32 @gets(i8* %6)
store i32 0, i32* %3
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
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %8
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 10
br label %24
24: ; preds = %16, %8
%25 = phi i1 [ false, %8 ], [ %23, %16 ]
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %8
29: ; preds = %24
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @readnum(i8* %0) {
%2 = tail call i32 @memset(i8* %0, i32 0, i32 8)
%3 = tail call i32 @gets(i8* %0)
br label %4
4: ; preds = %8, %1
%5 = phi i64 [ %9, %8 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
switch i8 %7, label %8 [
i8 0, label %10
i8 10, label %10
]
8: ; preds = %4
%9 = add nuw i64 %5, 1
br label %4
10: ; preds = %4, %4
%11 = trunc i64 %5 to i32
ret i32 %11
}