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

/* Variables and functions */
int check_arg_count(int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ putwin(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ report_count(int);
int /*<<< orphan*/ report_error(char *);
int /*<<< orphan*/ report_return(int /*<<< orphan*/);
scalar_t__ sscanf(char *, char *, int /*<<< orphan*/ **);
void cmd_putwin(int nargs, char **args) {
  FILE *fp;
  WINDOW *win;
  if (check_arg_count(nargs, 2) == 1)
    return;
  if (sscanf(args[0], "%p", &win) == 0) {
    report_count(1);
    report_error("BAD ARGUMENT");
    return;
  }
  if ((fp = fopen(args[1], "rw")) == NULL) {
    report_count(1);
    report_error("BAD FILE_ARGUMENT");
    return;
  }
  report_count(1);
  report_return(putwin(win, fp));
}


x86 assembly (clang, -O0):
<cmd_putwin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1040 <check_arg_count@plt>
cmp    $0x1,%eax
jne    119a <cmd_putwin+0x2a>
jmp    1231 <cmd_putwin+0xc1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe58(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x0,%rax
jne    11d6 <cmd_putwin+0x66>
mov    $0x1,%edi
call   1050 <report_count@plt>
lea    0xe37(%rip),%rdi
call   1070 <report_error@plt>
jmp    1231 <cmd_putwin+0xc1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1213 <cmd_putwin+0xa3>
mov    $0x1,%edi
call   1050 <report_count@plt>
lea    0xe0a(%rip),%rdi
call   1070 <report_error@plt>
jmp    1231 <cmd_putwin+0xc1>
mov    $0x1,%edi
call   1050 <report_count@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <putwin@plt>
mov    %eax,%edi
call   1030 <report_return@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_putwin>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    $0x2,%esi
call   1040 <check_arg_count@plt>
cmp    $0x1,%eax
je     11f7 <cmd_putwin+0x87>
mov    (%rbx),%rdi
lea    0xe6f(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1060 <sscanf@plt>
test   %rax,%rax
je     11d8 <cmd_putwin+0x68>
mov    0x8(%rbx),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    $0x1,%edi
call   1050 <report_count@plt>
test   %rbx,%rbx
je     11eb <cmd_putwin+0x7b>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1080 <putwin@plt>
mov    %eax,%edi
call   1030 <report_return@plt>
jmp    11f7 <cmd_putwin+0x87>
mov    $0x1,%edi
call   1050 <report_count@plt>
lea    0xe1a(%rip),%rdi
jmp    11f2 <cmd_putwin+0x82>
lea    0xe21(%rip),%rdi
call   1070 <report_error@plt>
add    $0x10,%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"rw\00"
@.str.3 = [18 x i8] c"BAD FILE_ARGUMENT\00"
define void @cmd_putwin(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca 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 2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
br label %35
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** %6)
%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 %35
20: ; preds = %11
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %5
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @report_count(i32 1)
%28 = call i32 @report_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %35
29: ; preds = %20
%30 = call i32 @report_count(i32 1)
%31 = load i32*, i32** %6
%32 = load i32*, i32** %5
%33 = call i32 @putwin(i32* %31, i32* %32)
%34 = call i32 @report_return(i32 %33)
br label %35
35: ; preds = %29, %26, %17, %10
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"rw\00"
@.str.3 = [18 x i8] c"BAD FILE_ARGUMENT\00"
define void @cmd_putwin(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 %26, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = call i64 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32** %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = call i32 @report_count(i32 1)
%13 = call i32 @report_error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %26
14: ; preds = %7
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
%19 = call i32 @report_count(i32 1)
br i1 %18, label %20, label %22
20: ; preds = %14
%21 = call i32 @report_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %26
22: ; preds = %14
%23 = load i32*, i32** %3
%24 = call i32 @putwin(i32* %23, i32* %17)
%25 = call i32 @report_return(i32 %24)
br label %26
26: ; preds = %2, %22, %20, %11
ret void
}