#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int str2int(char *, int, int *);
int strlen(char *);
main() {
  char buffer[256];
  int ans = 0, valid = 0;
  printf("Please input a positive integer: ");
  fflush(stdout);
  fgets(buffer, 256, stdin);
  buffer[strlen(buffer) - 1] = '\0';
  ans = str2int(buffer, 256, &valid);
  if (valid == 1) {
    printf("\nValid int: %d\n", ans);
  } else {
    printf("\nInvalid Input\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x114(%rbp)
movl   $0x0,-0x118(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1060 <fgets@plt>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
lea    -0x118(%rbp),%rdx
call   1030 <str2int@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x1,-0x118(%rbp)
jne    1209 <main+0xb9>
mov    -0x114(%rbp),%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1217 <main+0xc7>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x110,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe89(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <str2int@plt>
cmpl   $0x1,0xc(%rsp)
jne    11e1 <main+0x81>
lea    0xe4c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11ed <main+0x8d>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Please input a positive integer: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [16 x i8] c"\0AValid int: %d\0A\00"
@.str.2 = [16 x i8] c"\0AInvalid Input\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = call i32 @fflush(i32 %6)
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 256, i32 %9)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = call i32 @str2int(i8* %16, i32 256, i32* %4)
store i32 %17, i32* %3
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %0
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [34 x i8] c"Please input a positive integer: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [16 x i8] c"\0AValid int: %d\0A\00"
@str = [15 x i8] c"\0AInvalid Input\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdout
%7 = tail call i32 @fflush(i32 %6)
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %3, i32 256, i32 %8)
%10 = call i32 @strlen(i8* %3)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 @str2int(i8* %3, i32 256, i32* %2)
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %21
19: ; preds = %0
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
ret i32 0
}