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

/* Variables and functions */
int check_arg_count(int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ newterm(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ report_count(int);
int /*<<< orphan*/ report_error(char *);
int /*<<< orphan*/ report_ptr(int /*<<< orphan*/);
void cmd_newterm(int nargs, char **args) {
  FILE *in, *out;
  if (check_arg_count(nargs, 3) == 1)
    return;
  if ((in = fopen(args[1], "rw")) == NULL) {
    report_count(1);
    report_error("BAD FILE_ARGUMENT");
    return;
  }
  if ((out = fopen(args[2], "rw")) == NULL) {
    report_count(1);
    report_error("BAD FILE_ARGUMENT");
    return;
  }
  report_count(1);
  report_ptr(newterm(args[0], out, in));
}


x86 assembly (clang, -O0):
<cmd_newterm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x3,%esi
call   1040 <check_arg_count@plt>
cmp    $0x1,%eax
jne    118a <cmd_newterm+0x2a>
jmp    1229 <cmd_newterm+0xc9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c7 <cmd_newterm+0x67>
mov    $0x1,%edi
call   1050 <report_count@plt>
lea    0xe46(%rip),%rdi
call   1060 <report_error@plt>
jmp    1229 <cmd_newterm+0xc9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe2a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1204 <cmd_newterm+0xa4>
mov    $0x1,%edi
call   1050 <report_count@plt>
lea    0xe09(%rip),%rdi
call   1060 <report_error@plt>
jmp    1229 <cmd_newterm+0xc9>
mov    $0x1,%edi
call   1050 <report_count@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <newterm@plt>
mov    %eax,%edi
call   1030 <report_ptr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_newterm>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    $0x3,%esi
call   1040 <check_arg_count@plt>
cmp    $0x1,%eax
jne    117d <cmd_newterm+0x1d>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x8(%rbx),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d1 <cmd_newterm+0x71>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    $0x1,%edi
call   1050 <report_count@plt>
test   %r15,%r15
je     11db <cmd_newterm+0x7b>
mov    (%rbx),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <newterm@plt>
mov    %eax,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <report_ptr@plt>
mov    $0x1,%edi
call   1050 <report_count@plt>
lea    0xe21(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <report_error@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rw\00"
@.str.1 = [18 x i8] c"BAD FILE_ARGUMENT\00"
define void @cmd_newterm(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 3)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
br label %38
11: ; preds = %2
%12 = load i8**, i8*** %4
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %5
%16 = icmp eq i32* %15, null
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 ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %38
20: ; preds = %11
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %6
%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.1, i64 0, i64 0))
br label %38
29: ; preds = %20
%30 = call i32 @report_count(i32 1)
%31 = load i8**, i8*** %4
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = load i32*, i32** %6
%35 = load i32*, i32** %5
%36 = call i32 @newterm(i8* %33, i32* %34, i32* %35)
%37 = call i32 @report_ptr(i32 %36)
br label %38
38: ; preds = %29, %26, %17, %10
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rw\00"
@.str.1 = [18 x i8] c"BAD FILE_ARGUMENT\00"
define void @cmd_newterm(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @check_arg_count(i32 %0, i32 3)
%4 = icmp eq i32 %3, 1
br i1 %4, label %25, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = tail call i32 @report_count(i32 1)
%12 = tail call i32 @report_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %25
13: ; preds = %5
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32* %16, null
%18 = tail call i32 @report_count(i32 1)
br i1 %17, label %19, label %21
19: ; preds = %13
%20 = tail call i32 @report_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %25
21: ; preds = %13
%22 = load i8*, i8** %1
%23 = tail call i32 @newterm(i8* %22, i32* %16, i32* %8)
%24 = tail call i32 @report_ptr(i32 %23)
br label %25
25: ; preds = %2, %21, %19, %10
ret void
}