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

/* Variables and functions */
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 /*<<< orphan*/ wchgat(int /*<<< orphan*/ *, int, int, short,
                          int /*<<< orphan*/ *);
void cmd_wchgat(int nargs, char **args) {
  WINDOW *win;
  int n, attr;
  short colour;
  if (check_arg_count(nargs, 4) == 1)
    return;
  if (sscanf(args[0], "%p", &win) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if (sscanf(args[1], "%d", &n) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if (sscanf(args[2], "%d", &attr) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if (sscanf(args[3], "%hd", &colour) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  report_count(1);
  report_return(wchgat(win, n, attr, colour, NULL));
}


x86 assembly (clang, -O0):
<cmd_wchgat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x4,%esi
call   1050 <check_arg_count@plt>
cmp    $0x1,%eax
jne    118a <cmd_wchgat+0x2a>
jmp    12ae <cmd_wchgat+0x14e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe68(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    11c8 <cmd_wchgat+0x68>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xe45(%rip),%rdi
call   1080 <report_error@plt>
jmp    12ae <cmd_wchgat+0x14e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe39(%rip),%rsi
lea    -0x1c(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    1207 <cmd_wchgat+0xa7>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xe06(%rip),%rdi
call   1080 <report_error@plt>
jmp    12ae <cmd_wchgat+0x14e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdfa(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    1246 <cmd_wchgat+0xe6>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xdc7(%rip),%rdi
call   1080 <report_error@plt>
jmp    12ae <cmd_wchgat+0x14e>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdbe(%rip),%rsi
lea    -0x22(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    1285 <cmd_wchgat+0x125>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xd88(%rip),%rdi
call   1080 <report_error@plt>
jmp    12ae <cmd_wchgat+0x14e>
mov    $0x1,%edi
call   1060 <report_count@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
xor    %eax,%eax
mov    %eax,%r8d
movswl -0x22(%rbp),%ecx
call   1040 <wchgat@plt>
mov    %eax,%edi
call   1030 <report_return@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_wchgat>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    $0x4,%esi
call   1050 <check_arg_count@plt>
cmp    $0x1,%eax
je     1234 <cmd_wchgat+0xd4>
mov    (%rbx),%rdi
lea    0xe7b(%rip),%rsi
lea    0x18(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
test   %rax,%rax
je     121e <cmd_wchgat+0xbe>
mov    0x8(%rbx),%rdi
lea    0xe6b(%rip),%rsi
lea    0x14(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
test   %rax,%rax
je     121e <cmd_wchgat+0xbe>
mov    0x10(%rbx),%rdi
lea    0xe4f(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
test   %rax,%rax
je     121e <cmd_wchgat+0xbe>
mov    0x18(%rbx),%rdi
lea    0xe36(%rip),%rsi
lea    0xe(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1060 <report_count@plt>
test   %rbx,%rbx
je     1228 <cmd_wchgat+0xc8>
mov    0x18(%rsp),%rdi
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
movswl 0xe(%rsp),%ecx
xor    %r8d,%r8d
call   1040 <wchgat@plt>
mov    %eax,%edi
call   1030 <report_return@plt>
jmp    1234 <cmd_wchgat+0xd4>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xdd4(%rip),%rdi
call   1080 <report_error@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%p\00"
@.str.1 = [13 x i8] c"BAD ARGUMENT\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%hd\00"
define void @cmd_wchgat(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = load i32, i32* %3
%10 = call i32 @check_arg_count(i32 %9, i32 4)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %2
br label %57
13: ; preds = %2
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i64 (i8*, i8*, ...) @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 %57
22: ; preds = %13
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 (i8*, i8*, ...) @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, 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 %57
31: ; preds = %22
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i64 (i8*, i8*, ...) @sscanf(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, 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 %57
40: ; preds = %31
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i64 (i8*, i8*, ...) @sscanf(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i16* %8)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %40
%47 = call i32 @report_count(i32 1)
%48 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %57
49: ; preds = %40
%50 = call i32 @report_count(i32 1)
%51 = load i32*, i32** %5
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = load i16, i16* %8
%55 = call i32 @wchgat(i32* %51, i32 %52, i32 %53, i16 signext %54, i32* null)
%56 = call i32 @report_return(i32 %55)
br label %57
57: ; preds = %49, %46, %37, %28, %19, %12
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%p\00"
@.str.1 = [13 x i8] c"BAD ARGUMENT\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%hd\00"
define void @cmd_wchgat(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
%7 = bitcast i32** %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i16* %6 to i8*
%11 = tail call i32 @check_arg_count(i32 %0, i32 4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %51, label %13
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = call i64 (i8*, i8*, ...) @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32** %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%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 %51
20: ; preds = %13
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i64 (i8*, i8*, ...) @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%24 = icmp eq i64 %23, 0
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 ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %51
28: ; preds = %20
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = call i64 (i8*, i8*, ...) @sscanf(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 @report_count(i32 1)
%35 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %51
36: ; preds = %28
%37 = getelementptr inbounds i8*, i8** %1, i64 3
%38 = load i8*, i8** %37
%39 = call i64 (i8*, i8*, ...) @sscanf(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i16* %6)
%40 = icmp eq i64 %39, 0
%41 = call i32 @report_count(i32 1)
br i1 %40, label %42, label %44
42: ; preds = %36
%43 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %51
44: ; preds = %36
%45 = load i32*, i32** %3
%46 = load i32, i32* %4
%47 = load i32, i32* %5
%48 = load i16, i16* %6
%49 = call i32 @wchgat(i32* %45, i32 %46, i32 %47, i16 signext %48, i32* null)
%50 = call i32 @report_return(i32 %49)
br label %51
51: ; preds = %2, %44, %42, %33, %25, %17
ret void
}