#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
void read_number(char *message, int *dest) {
  char input[256];
  int result;
  do {
    printf("%s", message);
    fgets(input, 256, stdin);
    result = sscanf(input, "%d", dest);
    if (result < 1)
      printf("Invalid number!\n");
  } while (result != 1);
}


x86 assembly (clang, -O0):
<read_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1040 <fgets@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1050 <sscanf@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x1,-0x114(%rbp)
jge    11a7 <read_number+0x77>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ac <read_number+0x7c>
cmpl   $0x1,-0x114(%rbp)
jne    1143 <read_number+0x13>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_number>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
mov    0x2e8a(%rip),%r15
mov    %rsp,%rbx
lea    0xe9b(%rip),%r13
jmp    1175 <read_number+0x35>
nopw   0x0(%rax,%rax,1)
cmp    $0x1,%ebp
je     11b8 <read_number+0x78>
lea    0xe84(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   1060 <sscanf@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1170 <read_number+0x30>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
jmp    1170 <read_number+0x30>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [17 x i8] c"Invalid number!\0A\00"
define void @read_number(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
br label %7
7: ; preds = %21, %2
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %10, i32 256, i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%14 = load i32*, i32** %4
%15 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %7
br label %21
21: ; preds = %20
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 1
br i1 %23, label %7, label %24
24: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%d\00"
@str = [16 x i8] c"Invalid number!\00"
define void @read_number(i8* %0, i32* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %13, %2
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %4, i32 256, i32 %7)
%9 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %5, %11
%14 = icmp eq i32 %9, 1
br i1 %14, label %15, label %5
15: ; preds = %13
ret void
}