#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*/ assert(char *);
int atoi(char *);
int /*<<< orphan*/ fh_cli_hist_show(int);
int /*<<< orphan*/ fh_cli_print(char *, char *);
int /*<<< orphan*/ fh_cli_write(char *);
int strlen(char *);
int hist_cb(char *full_cmd, char **argv, int argc) {
  int n = -1;
  char *last_arg = argv[argc - 1];
  assert(full_cmd);
  if (last_arg[strlen(last_arg) - 1] == '?') {
    fh_cli_write("\n");
    fh_cli_print("<Enter>", "Get the last 10 commands");
    fh_cli_print("<Number>", "Get the last 'Number' commands");
    return 0;
  }
  if (argc == 1) {
    n = atoi(argv[0]);
  }
  fh_cli_hist_show(n);
  return 0;
}


x86 assembly (clang, -O0):
<hist_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3f,%eax
jne    1200 <hist_cb+0xa0>
lea    0xe37(%rip),%rdi
call   1050 <fh_cli_write@plt>
lea    0xe2d(%rip),%rdi
lea    0xe2e(%rip),%rsi
call   1080 <fh_cli_print@plt>
lea    0xe3b(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   1080 <fh_cli_print@plt>
movl   $0x0,-0x4(%rbp)
jmp    1228 <hist_cb+0xc8>
cmpl   $0x1,-0x1c(%rbp)
jne    1219 <hist_cb+0xb9>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <fh_cli_hist_show@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hist_cb>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
movslq %edx,%rax
mov    -0x8(%rsi,%rax,8),%rbx
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x3f,-0x1(%rax,%rbx,1)
jne    11bb <hist_cb+0x5b>
lea    0xe72(%rip),%rdi
call   1050 <fh_cli_write@plt>
lea    0xe68(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fh_cli_print@plt>
lea    0xe76(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fh_cli_print@plt>
jmp    11d4 <hist_cb+0x74>
mov    $0xffffffff,%edi
cmp    $0x1,%ebp
jne    11cf <hist_cb+0x6f>
mov    (%r14),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1030 <fh_cli_hist_show@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [8 x i8] c"<Enter>\00"
@.str.2 = [25 x i8] c"Get the last 10 commands\00"
@.str.3 = [9 x i8] c"<Number>\00"
@.str.4 = [31 x i8] c"Get the last 'Number' commands\00"
define i32 @hist_cb(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32 -1, i32* %8
%10 = load i8**, i8*** %6
%11 = load i32, i32* %7
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %10, i64 %13
%15 = load i8*, i8** %14
store i8* %15, i8** %9
%16 = load i8*, i8** %5
%17 = call i32 @assert(i8* %16)
%18 = load i8*, i8** %9
%19 = load i8*, i8** %9
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %18, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 63
br i1 %26, label %27, label %31
27: ; preds = %3
%28 = call i32 @fh_cli_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @fh_cli_print(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @fh_cli_print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %42
31: ; preds = %3
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8**, i8*** %6
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %8
br label %39
39: ; preds = %34, %31
%40 = load i32, i32* %8
%41 = call i32 @fh_cli_hist_show(i32 %40)
store i32 0, i32* %4
br label %42
42: ; preds = %39, %27
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [8 x i8] c"<Enter>\00"
@.str.2 = [25 x i8] c"Get the last 10 commands\00"
@.str.3 = [9 x i8] c"<Number>\00"
@.str.4 = [31 x i8] c"Get the last 'Number' commands\00"
define i32 @hist_cb(i8* %0, i8** nocapture %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8*, i8** %1, i64 %5
%7 = load i8*, i8** %6
%8 = tail call i32 @assert(i8* %0)
%9 = tail call i32 @strlen(i8* %7)
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 63
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = tail call i32 @fh_cli_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @fh_cli_print(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @fh_cli_print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %27
19: ; preds = %3
%20 = icmp eq i32 %2, 1
br i1 %20, label %21, label %24
21: ; preds = %19
%22 = load i8*, i8** %1
%23 = tail call i32 @atoi(i8* %22)
br label %24
24: ; preds = %21, %19
%25 = phi i32 [ %23, %21 ], [ -1, %19 ]
%26 = tail call i32 @fh_cli_hist_show(i32 %25)
br label %27
27: ; preds = %24, %15
ret i32 0
}