#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 /*<<< orphan*/ addchnstr(int /*<<< orphan*/ *, int);
int check_arg_count(int, int);
int /*<<< orphan*/ report_count(int);
int /*<<< orphan*/ report_error(char *);
int /*<<< orphan*/ report_return(int /*<<< orphan*/);
scalar_t__ sscanf(char *, char *, int *);
void cmd_addchnstr(int nargs, char **args) {
  int count;
  if (check_arg_count(nargs, 2) == 1)
    return;
  if (sscanf(args[1], "%d", &count) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  report_count(1);
  report_return(addchnstr((chtype *)args[0], count));
}


x86 assembly (clang, -O0):
<cmd_addchnstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1050 <check_arg_count@plt>
cmp    $0x1,%eax
jne    118a <cmd_addchnstr+0x2a>
jmp    11e7 <cmd_addchnstr+0x87>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe67(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    11c7 <cmd_addchnstr+0x67>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xe46(%rip),%rdi
call   1080 <report_error@plt>
jmp    11e7 <cmd_addchnstr+0x87>
mov    $0x1,%edi
call   1060 <report_count@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
call   1040 <addchnstr@plt>
mov    %eax,%edi
call   1030 <report_return@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_addchnstr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0x2,%esi
call   1050 <check_arg_count@plt>
cmp    $0x1,%eax
je     11be <cmd_addchnstr+0x5e>
mov    0x8(%r14),%rdi
lea    0xe7f(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1070 <sscanf@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1060 <report_count@plt>
test   %rbx,%rbx
je     11b2 <cmd_addchnstr+0x52>
mov    (%r14),%rdi
mov    0x4(%rsp),%esi
call   1040 <addchnstr@plt>
mov    %eax,%edi
call   1030 <report_return@plt>
jmp    11be <cmd_addchnstr+0x5e>
lea    0xe4a(%rip),%rdi
call   1080 <report_error@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"BAD ARGUMENT\00"
define void @cmd_addchnstr(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @check_arg_count(i32 %0, i32 2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i64 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = icmp eq i64 %10, 0
%12 = call i32 @report_count(i32 1)
br i1 %11, label %13, label %15
13: ; preds = %7
%14 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %21
15: ; preds = %7
%16 = bitcast i8** %1 to i32**
%17 = load i32*, i32** %16
%18 = load i32, i32* %3
%19 = call i32 @addchnstr(i32* %17, i32 %18)
%20 = call i32 @report_return(i32 %19)
br label %21
21: ; preds = %2, %15, %13
ret void
}