#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*/ str;

/* Variables and functions */
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char readlong(char num[]) {
  char l, i;
  char str[111];
  memset(str, 0, sizeof(str));
  gets(str);
  if (str[0] == '0' && !str[1])
    return 0;
  for (l = 0; str[l];)
    l++;
  for (i = 110; i > 110 - l; i--) {
    num[i] = str[i - 111 + l] - 48;
  }
  return 1;
}


x86 assembly (clang, -O0):
<readlong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x6f,%edx
call   1030 <memset@plt>
lea    -0x90(%rbp),%rdi
call   1040 <gets@plt>
movsbl -0x90(%rbp),%eax
cmp    $0x30,%eax
jne    1174 <readlong+0x54>
cmpb   $0x0,-0x8f(%rbp)
jne    1174 <readlong+0x54>
movb   $0x0,-0x1(%rbp)
jmp    11ec <readlong+0xcc>
movb   $0x0,-0x11(%rbp)
movsbq -0x11(%rbp),%rax
cmpb   $0x0,-0x90(%rbp,%rax,1)
je     1198 <readlong+0x78>
mov    -0x11(%rbp),%al
add    $0x1,%al
mov    %al,-0x11(%rbp)
jmp    1178 <readlong+0x58>
movb   $0x6e,-0x12(%rbp)
movsbl -0x12(%rbp),%eax
movsbl -0x11(%rbp),%edx
mov    $0x6e,%ecx
sub    %edx,%ecx
cmp    %ecx,%eax
jle    11e8 <readlong+0xc8>
movsbl -0x12(%rbp),%eax
sub    $0x6f,%eax
movsbl -0x11(%rbp),%ecx
add    %ecx,%eax
cltq
movsbl -0x90(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movsbq -0x12(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x12(%rbp),%al
add    $0xff,%al
mov    %al,-0x12(%rbp)
jmp    119c <readlong+0x7c>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readlong>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rdi,%rbp
mov    %rsp,%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x6f,%edx
call   1030 <memset@plt>
mov    %rbx,%rdi
call   1040 <gets@plt>
mov    (%rsp),%al
cmp    $0x30,%al
jne    1156 <readlong+0x36>
cmpb   $0x0,0x1(%rsp)
je     11ae <readlong+0x8e>
test   %al,%al
je     116e <readlong+0x4e>
xor    %eax,%eax
nopl   0x0(%rax)
add    $0x1,%al
movsbq %al,%rcx
cmpb   $0x0,(%rsp,%rcx,1)
jne    1160 <readlong+0x40>
jmp    1170 <readlong+0x50>
xor    %eax,%eax
mov    $0x1,%r14b
test   %al,%al
jle    11ae <readlong+0x8e>
movsbl %al,%eax
mov    $0x6e,%edx
mov    $0x6e,%ecx
sub    %eax,%ecx
add    $0xffffff91,%eax
nopl   0x0(%rax)
lea    (%rax,%rdx,1),%esi
movslq %esi,%rsi
movzbl (%rsp,%rsi,1),%ebx
add    $0xd0,%bl
movslq %edx,%rdx
mov    %bl,0x0(%rbp,%rdx,1)
add    $0xff,%dl
movsbl %dl,%edx
cmp    %edx,%ecx
jl     1190 <readlong+0x70>
mov    %r14d,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @readlong(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = alloca [111 x i8]
store i8* %0, i8** %3
%7 = getelementptr inbounds [111 x i8], [111 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 111)
%9 = getelementptr inbounds [111 x i8], [111 x i8]* %6, i64 0, i64 0
%10 = call i32 @gets(i8* %9)
%11 = getelementptr inbounds [111 x i8], [111 x i8]* %6, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 48
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = getelementptr inbounds [111 x i8], [111 x i8]* %6, i64 0, i64 1
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %15
store i8 0, i8* %2
br label %59
20: ; preds = %15, %1
store i8 0, i8* %4
br label %21
21: ; preds = %27, %20
%22 = load i8, i8* %4
%23 = sext i8 %22 to i64
%24 = getelementptr inbounds [111 x i8], [111 x i8]* %6, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i8, i8* %4
%29 = add i8 %28, 1
store i8 %29, i8* %4
br label %21
30: ; preds = %21
store i8 110, i8* %5
br label %31
31: ; preds = %55, %30
%32 = load i8, i8* %5
%33 = sext i8 %32 to i32
%34 = load i8, i8* %4
%35 = sext i8 %34 to i32
%36 = sub nsw i32 110, %35
%37 = icmp sgt i32 %33, %36
br i1 %37, label %38, label %58
38: ; preds = %31
%39 = load i8, i8* %5
%40 = sext i8 %39 to i32
%41 = sub nsw i32 %40, 111
%42 = load i8, i8* %4
%43 = sext i8 %42 to i32
%44 = add nsw i32 %41, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [111 x i8], [111 x i8]* %6, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = sub nsw i32 %48, 48
%50 = trunc i32 %49 to i8
%51 = load i8*, i8** %3
%52 = load i8, i8* %5
%53 = sext i8 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 %50, i8* %54
br label %55
55: ; preds = %38
%56 = load i8, i8* %5
%57 = add i8 %56, -1
store i8 %57, i8* %5
br label %31
58: ; preds = %31
store i8 1, i8* %2
br label %59
59: ; preds = %58, %19
%60 = load i8, i8* %2
ret i8 %60
}

LLVM IR (-O2):
define signext i8 @readlong(i8* nocapture writeonly %0) {
%2 = alloca [111 x i8]
%3 = getelementptr inbounds [111 x i8], [111 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 111)
%5 = call i32 @gets(i8* %3)
%6 = load i8, i8* %3
%7 = icmp ne i8 %6, 48
%8 = getelementptr inbounds [111 x i8], [111 x i8]* %2, i64 0, i64 1
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
%11 = select i1 %7, i1 true, i1 %10
br i1 %11, label %12, label %41
12: ; preds = %1
%13 = icmp eq i8 %6, 0
br i1 %13, label %21, label %14
14: ; preds = %12, %14
%15 = phi i8 [ %20, %14 ], [ 1, %12 ]
%16 = sext i8 %15 to i64
%17 = getelementptr inbounds [111 x i8], [111 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
%20 = add i8 %15, 1
br i1 %19, label %21, label %14
21: ; preds = %14, %12
%22 = phi i8 [ 0, %12 ], [ %15, %14 ]
%23 = sext i8 %22 to i32
%24 = sub nsw i32 110, %23
%25 = icmp sgt i8 %22, 0
br i1 %25, label %26, label %41
26: ; preds = %21
%27 = add nsw i32 %23, -111
br label %28
28: ; preds = %26, %28
%29 = phi i32 [ 110, %26 ], [ %39, %28 ]
%30 = add nsw i32 %27, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [111 x i8], [111 x i8]* %2, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = add i8 %33, -48
%35 = sext i32 %29 to i64
%36 = getelementptr inbounds i8, i8* %0, i64 %35
store i8 %34, i8* %36
%37 = shl nsw i32 %29, 24
%38 = add i32 %37, -16777216
%39 = ashr exact i32 %38, 24
%40 = icmp slt i32 %24, %39
br i1 %40, label %28, label %41
41: ; preds = %28, %21, %1
%42 = phi i8 [ 0, %1 ], [ 1, %21 ], [ 1, %28 ]
ret i8 %42
}