#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;
typedef int /*<<< orphan*/ WINDOW;

/* Variables and functions */
int check_arg_count(int, 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 /*<<< orphan*/ **);
int /*<<< orphan*/ winchstr(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
void cmd_winchstr(int nargs, char **args) {
  WINDOW *win;
  chtype string[256];
  if (check_arg_count(nargs, 1) == 1)
    return;
  if (sscanf(args[0], "%p", &win) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  report_count(2);
  report_return(winchstr(win, string));
  report_nstr(string);
}


x86 assembly (clang, -O0):
<cmd_winchstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%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    119d <cmd_winchstr+0x2d>
jmp    1206 <cmd_winchstr+0x96>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe55(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    11d9 <cmd_winchstr+0x69>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xe34(%rip),%rdi
call   1080 <report_error@plt>
jmp    1206 <cmd_winchstr+0x96>
mov    $0x2,%edi
call   1060 <report_count@plt>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1090 <winchstr@plt>
mov    %eax,%edi
call   1040 <report_return@plt>
lea    -0x420(%rbp),%rdi
call   1030 <report_nstr@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_winchstr>:
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%rbx
mov    $0x1,%esi
call   1050 <check_arg_count@plt>
cmp    $0x1,%eax
je     11e6 <cmd_winchstr+0x76>
mov    (%rbx),%rdi
lea    0xe6c(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
je     11d0 <cmd_winchstr+0x60>
mov    $0x2,%edi
call   1060 <report_count@plt>
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1090 <winchstr@plt>
mov    %eax,%edi
call   1040 <report_return@plt>
mov    %rbx,%rdi
call   1030 <report_nstr@plt>
jmp    11e6 <cmd_winchstr+0x76>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xe22(%rip),%rdi
call   1080 <report_error@plt>
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%p\00"
@.str.1 = [13 x i8] c"BAD ARGUMENT\00"
define void @cmd_winchstr(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca [256 x i32]
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 %28
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 %28
20: ; preds = %11
%21 = call i32 @report_count(i32 2)
%22 = load i32*, i32** %5
%23 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 0
%24 = call i32 @winchstr(i32* %22, i32* %23)
%25 = call i32 @report_return(i32 %24)
%26 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 0
%27 = call i32 @report_nstr(i32* %26)
br label %28
28: ; preds = %20, %17, %10
ret void
}

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