#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 /*<<< orphan*/ EXIT_FAILURE;
char *close_cmd(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
void write_cmd(char *cmds) {
  FILE *f = fopen("clips.in", "w");
  if (!f) {
    fprintf(stderr, "Cannot open CLIPS input");
    exit(EXIT_FAILURE);
  }
  cmds = close_cmd(cmds);
  fprintf(f, "%s", cmds);
  fclose(f);
  free(cmds);
}


x86 assembly (clang, -O0):
<write_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <write_cmd+0x54>
mov    0x2e4b(%rip),%rax
movslq (%rax),%rdi
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <close_cmd@plt>
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_cmd>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe82(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11bf <write_cmd+0x4f>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <close_cmd@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>
mov    0x2e1a(%rip),%rax
movslq (%rax),%rcx
lea    0xe3b(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"clips.in\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Cannot open CLIPS input\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%s\00"
define void @write_cmd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i32*
%11 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = call i8* @close_cmd(i8* %15)
store i8* %16, i8** %2
%17 = load i32*, i32** %3
%18 = load i8*, i8** %2
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
%22 = load i8*, i8** %2
%23 = call i32 @free(i8* %22)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"clips.in\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Cannot open CLIPS input\00"
@EXIT_FAILURE = global i32 0
define void @write_cmd(i8* %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 23, i64 1, i32* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = tail call i8* @close_cmd(i8* %0)
%13 = tail call i32 @fputs(i8* %12, i32* %2)
%14 = tail call i32 @fclose(i32* %2)
%15 = tail call i32 @free(i8* %12)
ret void
}