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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int note_number(void) {
  int num;
  char buf[15] = {0};
  printf("Note number: ");
  if (!fgets(buf, sizeof(buf), stdin))
    return -1;
  num = atoi(buf);
  if (num >= 5) {
    fprintf(stderr, "Number too large!\n");
    return -1;
  }
  return num;
}


x86 assembly (clang, -O0):
<note_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x17(%rbp),%rdi
xor    %esi,%esi
mov    $0xf,%edx
call   1040 <memset@plt>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
lea    -0x17(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    $0xf,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11a0 <note_number+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <note_number+0x8d>
lea    -0x17(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jl     11d7 <note_number+0x87>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <note_number+0x8d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<note_number>:
sub    $0x18,%rsp
movq   $0x0,0xf(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
mov    $0xf,%esi
call   1040 <fgets@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     11ae <note_number+0x6e>
lea    0x8(%rsp),%rdi
call   1060 <atoi@plt>
cmp    $0x5,%eax
jl     11ae <note_number+0x6e>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Note number: \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Number too large!\0A\00"
define i32 @note_number() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [15 x i8]
%4 = bitcast [15 x i8]* %3 to i8*
%5 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 15, i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %0
store i32 -1, i32* %1
br label %21
11: ; preds = %0
%12 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%13 = call i32 @atoi(i8* %12)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp sge i32 %14, 5
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %21
19: ; preds = %11
%20 = load i32, i32* %2
store i32 %20, i32* %1
br label %21
21: ; preds = %19, %16, %10
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [14 x i8] c"Note number: \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [19 x i8] c"Number too large!\0A\00"
define i32 @note_number() {
%1 = alloca [15 x i8]
%2 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 15, i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %0
%8 = call i32 @atoi(i8* %2)
%9 = icmp sgt i32 %8, 4
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %7, %0, %10
%14 = phi i32 [ -1, %10 ], [ -1, %0 ], [ %8, %7 ]
ret i32 %14
}