#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_ptr(int /*<<< orphan*/);
scalar_t__ sscanf(char *, char *, int *);
int /*<<< orphan*/ subpad(int /*<<< orphan*/ *, int, int, int, int);
void cmd_subpad(int nargs, char **args) {
  WINDOW *pad;
  int lines, cols, begin_y, begin_x;
  if (check_arg_count(nargs, 5) == 1)
    return;
  if (sscanf(args[0], "%p", &pad) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if (sscanf(args[1], "%d", &lines) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if (sscanf(args[2], "%d", &cols) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if (sscanf(args[3], "%d", &begin_y) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if (sscanf(args[4], "%d", &begin_x) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  report_count(1);
  report_ptr(subpad(pad, lines, cols, begin_y, begin_x));
}


x86 assembly (clang, -O0):
<cmd_subpad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x5,%esi
call   1050 <check_arg_count@plt>
cmp    $0x1,%eax
jne    118a <cmd_subpad+0x2a>
jmp    12e1 <cmd_subpad+0x181>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x18(%rbp),%rdx
lea    0xe64(%rip),%rsi
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    11c6 <cmd_subpad+0x66>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xe47(%rip),%rdi
call   1080 <report_error@plt>
jmp    12e1 <cmd_subpad+0x181>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3b(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    1203 <cmd_subpad+0xa3>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xe0a(%rip),%rdi
call   1080 <report_error@plt>
jmp    12e1 <cmd_subpad+0x181>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdfe(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    1240 <cmd_subpad+0xe0>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xdcd(%rip),%rdi
call   1080 <report_error@plt>
jmp    12e1 <cmd_subpad+0x181>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdc1(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    127d <cmd_subpad+0x11d>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xd90(%rip),%rdi
call   1080 <report_error@plt>
jmp    12e1 <cmd_subpad+0x181>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xd84(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jne    12ba <cmd_subpad+0x15a>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xd53(%rip),%rdi
call   1080 <report_error@plt>
jmp    12e1 <cmd_subpad+0x181>
mov    $0x1,%edi
call   1060 <report_count@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1040 <subpad@plt>
mov    %eax,%edi
call   1030 <report_ptr@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_subpad>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    $0x5,%esi
call   1050 <check_arg_count@plt>
cmp    $0x1,%eax
je     1247 <cmd_subpad+0xe7>
mov    (%rbx),%rdi
lea    0xe7b(%rip),%rsi
lea    0x18(%rsp),%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
je     1231 <cmd_subpad+0xd1>
mov    0x8(%rbx),%rdi
lea    0xe6d(%rip),%rsi
lea    0x14(%rsp),%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
je     1231 <cmd_subpad+0xd1>
mov    0x10(%rbx),%rdi
lea    0xe53(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
je     1231 <cmd_subpad+0xd1>
mov    0x18(%rbx),%rdi
lea    0xe39(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
je     1231 <cmd_subpad+0xd1>
mov    0x20(%rbx),%rdi
lea    0xe1f(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1070 <sscanf@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1060 <report_count@plt>
test   %rbx,%rbx
je     123b <cmd_subpad+0xdb>
mov    0x18(%rsp),%rdi
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
call   1040 <subpad@plt>
mov    %eax,%edi
call   1030 <report_ptr@plt>
jmp    1247 <cmd_subpad+0xe7>
mov    $0x1,%edi
call   1060 <report_count@plt>
lea    0xdc1(%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"
define void @cmd_subpad(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = load i32, i32* %3
%11 = call i32 @check_arg_count(i32 %10, i32 5)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %2
br label %69
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = bitcast i32** %5 to i32*
%19 = call i64 @sscanf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 @report_count(i32 1)
%23 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %69
24: ; preds = %14
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @sscanf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = call i32 @report_count(i32 1)
%32 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %69
33: ; preds = %24
%34 = load i8**, i8*** %4
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i64 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = call i32 @report_count(i32 1)
%41 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %69
42: ; preds = %33
%43 = load i8**, i8*** %4
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = call i64 @sscanf(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = call i32 @report_count(i32 1)
%50 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %69
51: ; preds = %42
%52 = load i8**, i8*** %4
%53 = getelementptr inbounds i8*, i8** %52, i64 4
%54 = load i8*, i8** %53
%55 = call i64 @sscanf(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = call i32 @report_count(i32 1)
%59 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %69
60: ; preds = %51
%61 = call i32 @report_count(i32 1)
%62 = load i32*, i32** %5
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = load i32, i32* %8
%66 = load i32, i32* %9
%67 = call i32 @subpad(i32* %62, i32 %63, i32 %64, i32 %65, i32 %66)
%68 = call i32 @report_ptr(i32 %67)
br label %69
69: ; preds = %60, %57, %48, %39, %30, %21, %13
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"
define void @cmd_subpad(i32 %0, i8** nocapture %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32** %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = tail call i32 @check_arg_count(i32 %0, i32 5)
%14 = icmp eq i32 %13, 1
br i1 %14, label %63, label %15
15: ; preds = %2
%16 = load i8*, i8** %1
%17 = bitcast i32** %3 to i32*
%18 = call i64 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = call i32 @report_count(i32 1)
%22 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %63
23: ; preds = %15
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%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 = %23
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = call i64 @sscanf(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @report_count(i32 1)
%38 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %63
39: ; preds = %31
%40 = getelementptr inbounds i8*, i8** %1, i64 3
%41 = load i8*, i8** %40
%42 = call i64 @sscanf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = call i32 @report_count(i32 1)
%46 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %63
47: ; preds = %39
%48 = getelementptr inbounds i8*, i8** %1, i64 4
%49 = load i8*, i8** %48
%50 = call i64 @sscanf(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%51 = icmp eq i64 %50, 0
%52 = call i32 @report_count(i32 1)
br i1 %51, label %53, label %55
53: ; preds = %47
%54 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %63
55: ; preds = %47
%56 = load i32*, i32** %3
%57 = load i32, i32* %4
%58 = load i32, i32* %5
%59 = load i32, i32* %6
%60 = load i32, i32* %7
%61 = call i32 @subpad(i32* %56, i32 %57, i32 %58, i32 %59, i32 %60)
%62 = call i32 @report_ptr(i32 %61)
br label %63
63: ; preds = %2, %55, %53, %44, %36, %28, %20
ret void
}