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

/* Variables and functions */
int check_arg_count(int, int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ mvinchnstr(int, int, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ report_count(int);
int /*<<< orphan*/ report_error(char *);
int /*<<< orphan*/ report_nstr(int /*<<< orphan*/ *);
int /*<<< orphan*/ report_return(int /*<<< orphan*/);
scalar_t__ sscanf(char *, char *, int *);
void cmd_mvinchnstr(int nargs, char **args) {
  int y, x, count;
  chtype *string;
  if (check_arg_count(nargs, 3) == 1)
    return;
  if (sscanf(args[0], "%d", &y) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if (sscanf(args[1], "%d", &x) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if (sscanf(args[2], "%d", &count) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if ((string = malloc((count + 1) * sizeof(chtype))) == NULL) {
    report_count(1);
    report_error("MALLOC_FAILED");
    return;
  }
  report_count(2);
  report_return(mvinchnstr(y, x, string, count));
  report_nstr(string);
  free(string);
}


x86 assembly (clang, -O0):
<cmd_mvinchnstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x3,%esi
call   1060 <check_arg_count@plt>
cmp    $0x1,%eax
jne    11ba <cmd_mvinchnstr+0x2a>
jmp    12e1 <cmd_mvinchnstr+0x151>
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_mvinchnstr+0x66>
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xe17(%rip),%rdi
call   10a0 <report_error@plt>
jmp    12e1 <cmd_mvinchnstr+0x151>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdfb(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x0,%rax
jne    1233 <cmd_mvinchnstr+0xa3>
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xdda(%rip),%rdi
call   10a0 <report_error@plt>
jmp    12e1 <cmd_mvinchnstr+0x151>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdbe(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x0,%rax
jne    1270 <cmd_mvinchnstr+0xe0>
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xd9d(%rip),%rdi
call   10a0 <report_error@plt>
jmp    12e1 <cmd_mvinchnstr+0x151>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12ac <cmd_mvinchnstr+0x11c>
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xd6e(%rip),%rdi
call   10a0 <report_error@plt>
jmp    12e1 <cmd_mvinchnstr+0x151>
mov    $0x2,%edi
call   1080 <report_count@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   10b0 <mvinchnstr@plt>
mov    %eax,%edi
call   1050 <report_return@plt>
mov    -0x28(%rbp),%rdi
call   1040 <report_nstr@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_mvinchnstr>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    $0x3,%esi
call   1060 <check_arg_count@plt>
cmp    $0x1,%eax
je     1261 <cmd_mvinchnstr+0xd1>
mov    (%rbx),%rdi
lea    0xe4b(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1090 <sscanf@plt>
test   %rax,%rax
je     124b <cmd_mvinchnstr+0xbb>
mov    0x8(%rbx),%rdi
lea    0xe2d(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1090 <sscanf@plt>
test   %rax,%rax
je     124b <cmd_mvinchnstr+0xbb>
mov    0x10(%rbx),%rdi
lea    0xe13(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1090 <sscanf@plt>
test   %rax,%rax
je     124b <cmd_mvinchnstr+0xbb>
mov    0x4(%rsp),%eax
lea    0x4(,%rax,4),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1267 <cmd_mvinchnstr+0xd7>
mov    %rax,%rbx
mov    $0x2,%edi
call   1080 <report_count@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%ecx
mov    %rbx,%rdx
call   10b0 <mvinchnstr@plt>
mov    %eax,%edi
call   1050 <report_return@plt>
mov    %rbx,%rdi
call   1040 <report_nstr@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1261 <cmd_mvinchnstr+0xd1>
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xda7(%rip),%rdi
call   10a0 <report_error@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x1,%edi
call   1080 <report_count@plt>
lea    0xd98(%rip),%rdi
jmp    125c <cmd_mvinchnstr+0xcc>

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_mvinchnstr(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = call i32 @check_arg_count(i32 %9, i32 3)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %2
br label %63
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i64 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @report_count(i32 1)
%21 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %63
22: ; preds = %13
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 @report_count(i32 1)
%30 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %63
31: ; preds = %22
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i64 @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = call i32 @report_count(i32 1)
%39 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %63
40: ; preds = %31
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = mul i64 %43, 4
%45 = trunc i64 %44 to i32
%46 = call i32* @malloc(i32 %45)
store i32* %46, i32** %8
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %51
48: ; preds = %40
%49 = call i32 @report_count(i32 1)
%50 = call i32 @report_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %63
51: ; preds = %40
%52 = call i32 @report_count(i32 2)
%53 = load i32, i32* %5
%54 = load i32, i32* %6
%55 = load i32*, i32** %8
%56 = load i32, i32* %7
%57 = call i32 @mvinchnstr(i32 %53, i32 %54, i32* %55, i32 %56)
%58 = call i32 @report_return(i32 %57)
%59 = load i32*, i32** %8
%60 = call i32 @report_nstr(i32* %59)
%61 = load i32*, i32** %8
%62 = call i32 @free(i32* %61)
br label %63
63: ; preds = %51, %48, %37, %28, %19, %12
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_mvinchnstr(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 @check_arg_count(i32 %0, i32 3)
%10 = icmp eq i32 %9, 1
br i1 %10, label %52, label %11
11: ; preds = %2
%12 = load i8*, i8** %1
%13 = call i64 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @report_count(i32 1)
%17 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %52
18: ; preds = %11
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @report_count(i32 1)
%25 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %52
26: ; preds = %18
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = call i64 @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = call i32 @report_count(i32 1)
%33 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %52
34: ; preds = %26
%35 = load i32, i32* %5
%36 = shl i32 %35, 2
%37 = add i32 %36, 4
%38 = call i32* @malloc(i32 %37)
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = call i32 @report_count(i32 1)
%42 = call i32 @report_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %52
43: ; preds = %34
%44 = call i32 @report_count(i32 2)
%45 = load i32, i32* %3
%46 = load i32, i32* %4
%47 = load i32, i32* %5
%48 = call i32 @mvinchnstr(i32 %45, i32 %46, i32* %38, i32 %47)
%49 = call i32 @report_return(i32 %48)
%50 = call i32 @report_nstr(i32* %38)
%51 = call i32 @free(i32* %38)
br label %52
52: ; preds = %2, %43, %40, %31, %23, %15
ret void
}