#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 check_arg_count(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ innstr(char *, int);
char *malloc(int);
int /*<<< orphan*/ report_count(int);
int /*<<< orphan*/ report_error(char *);
int /*<<< orphan*/ report_int(int /*<<< orphan*/);
int /*<<< orphan*/ report_status(char *);
scalar_t__ sscanf(char *, char *, int *);
void cmd_innstr(int nargs, char **args) {
  int limit;
  char *string;
  if (check_arg_count(nargs, 1) == 1)
    return;
  if (sscanf(args[0], "%d", &limit) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if ((string = malloc(limit + 1)) == NULL) {
    report_count(1);
    report_error("MALLOC_FAILED");
    return;
  }
  report_count(2);
  report_int(innstr(string, limit));
  report_status(string);
  free(string);
}


x86 assembly (clang, -O0):
<cmd_innstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1050 <check_arg_count@plt>
cmp    $0x1,%eax
jne    11ba <cmd_innstr+0x2a>
jmp    1259 <cmd_innstr+0xc9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe38(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x0,%rax
jne    11f6 <cmd_innstr+0x66>
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xe17(%rip),%rdi
call   10a0 <report_error@plt>
jmp    1259 <cmd_innstr+0xc9>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    122a <cmd_innstr+0x9a>
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xdf0(%rip),%rdi
call   10a0 <report_error@plt>
jmp    1259 <cmd_innstr+0xc9>
mov    $0x2,%edi
call   1080 <report_count@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <innstr@plt>
mov    %eax,%edi
call   10b0 <report_int@plt>
mov    -0x20(%rbp),%rdi
call   1040 <report_status@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_innstr>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    $0x1,%esi
call   1050 <check_arg_count@plt>
cmp    $0x1,%eax
je     1230 <cmd_innstr+0xa0>
mov    (%rbx),%rdi
lea    0xe4b(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1090 <sscanf@plt>
test   %rax,%rax
je     1207 <cmd_innstr+0x77>
mov    0xc(%rsp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     121a <cmd_innstr+0x8a>
mov    %rax,%rbx
mov    $0x2,%edi
call   1080 <report_count@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1070 <innstr@plt>
mov    %eax,%edi
call   10b0 <report_int@plt>
mov    %rbx,%rdi
call   1040 <report_status@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1230 <cmd_innstr+0xa0>
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xdeb(%rip),%rdi
jmp    122b <cmd_innstr+0x9b>
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xde5(%rip),%rdi
call   10a0 <report_error@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"BAD ARGUMENT\00"
@.str.2 = [14 x i8] c"MALLOC_FAILED\00"
define void @cmd_innstr(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = call i32 @check_arg_count(i32 %7, i32 1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
br label %38
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i64 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = call i32 @report_count(i32 1)
%19 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %38
20: ; preds = %11
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %6
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @report_count(i32 1)
%27 = call i32 @report_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %38
28: ; preds = %20
%29 = call i32 @report_count(i32 2)
%30 = load i8*, i8** %6
%31 = load i32, i32* %5
%32 = call i32 @innstr(i8* %30, i32 %31)
%33 = call i32 @report_int(i32 %32)
%34 = load i8*, i8** %6
%35 = call i32 @report_status(i8* %34)
%36 = load i8*, i8** %6
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %28, %25, %17, %10
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"BAD ARGUMENT\00"
@.str.2 = [14 x i8] c"MALLOC_FAILED\00"
define void @cmd_innstr(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @check_arg_count(i32 %0, i32 1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %29, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = call i64 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = call i32 @report_count(i32 1)
%13 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %29
14: ; preds = %7
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
%17 = call i8* @malloc(i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = call i32 @report_count(i32 1)
%21 = call i32 @report_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %29
22: ; preds = %14
%23 = call i32 @report_count(i32 2)
%24 = load i32, i32* %3
%25 = call i32 @innstr(i8* %17, i32 %24)
%26 = call i32 @report_int(i32 %25)
%27 = call i32 @report_status(i8* %17)
%28 = call i32 @free(i8* %17)
br label %29
29: ; preds = %2, %22, %19, %11
ret void
}