#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 /*<<< orphan*/ printf(char *);
int scanf(char *, ...);
int getSize() {
  int size;
  printf("Please enter size:");
  for (; scanf("%d", &size) != 1 || size < 0; scanf("%*s"))
    printf("\nError: Please enter size:");
  printf("\n");
  return size;
}


x86 assembly (clang, -O0):
<getSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xedc(%rip),%rdi
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%al
cmp    $0x1,%ecx
mov    %al,-0x5(%rbp)
jne    1160 <getSize+0x40>
cmpl   $0x0,-0x4(%rbp)
setl   %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
test   $0x1,%al
jne    1170 <getSize+0x50>
jmp    118f <getSize+0x6f>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    1134 <getSize+0x14>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSize>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xecc(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1163 <getSize+0x33>
cmpl   $0x0,0x4(%rsp)
jns    11ab <getSize+0x7b>
lea    0xe99(%rip),%r14
lea    0xead(%rip),%r15
lea    0xe88(%rip),%r12
lea    0x4(%rsp),%rbx
nopl   (%rax)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1180 <getSize+0x50>
cmpl   $0x0,0x4(%rsp)
js     1180 <getSize+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Please enter size:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"\0AError: Please enter size:\00"
@.str.3 = [4 x i8] c"%*s\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @getSize() {
%1 = alloca i32
%2 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %13, %0
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = icmp ne i32 %4, 1
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 0
br label %9
9: ; preds = %6, %3
%10 = phi i1 [ true, %3 ], [ %8, %6 ]
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %3
15: ; preds = %9
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [19 x i8] c"Please enter size:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"\0AError: Please enter size:\00"
@.str.3 = [4 x i8] c"%*s\00"
define i32 @getSize() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = icmp ne i32 %4, 1
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 0
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %9, label %17
9: ; preds = %0, %9
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%13 = icmp ne i32 %12, 1
%14 = load i32, i32* %1
%15 = icmp slt i32 %14, 0
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %9, label %17
17: ; preds = %9, %0
%18 = call i32 @putchar(i32 10)
%19 = load i32, i32* %1
ret i32 %19
}