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

/* Variables and functions */
int atoi(char *);
char *create_new_file(char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ remove_files_maybe(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *path_filename, *new;
  char *mode = (char *)0;
  int number_to_queue = 0;
  int exit_usage = 0;
  if (argc < 3) {
    exit_usage = 1;
  } else if (!(number_to_queue = atoi(argv[2]))) {
    exit_usage = 1;
  }
  if (exit_usage) {
    fprintf(stderr, "Usage: %s /path/filename number_to_queue [mode]\n",
            argv[0]);
    fprintf(stderr, "Note: mode must be octal\n");
    exit(1);
  }
  path_filename = argv[1];
  if (argc == 4)
    mode = argv[3];
  new = create_new_file(path_filename, mode);
  if (new) {
    printf("%s\n", new);
    remove_files_maybe(path_filename, number_to_queue);
    return 0;
  } else {
    fprintf(stderr, "ERROR: %s cannot create next file for (%s).\n", argv[0],
            path_filename);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11a2 <main+0x42>
movl   $0x1,-0x30(%rbp)
jmp    11c7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jne    11c2 <main+0x62>
movl   $0x1,-0x30(%rbp)
jmp    11c7 <main+0x67>
cmpl   $0x0,-0x30(%rbp)
je     1210 <main+0xb0>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1232 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <create_new_file@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1272 <main+0x112>
mov    -0x20(%rbp),%rsi
lea    0xdf2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <remove_files_maybe@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jl     11c6 <main+0x66>
mov    %edi,%ebp
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
je     11c6 <main+0x66>
mov    %eax,%r15d
mov    0x8(%rbx),%r14
cmp    $0x4,%ebp
jne    1190 <main+0x30>
mov    0x18(%rbx),%rsi
jmp    1192 <main+0x32>
xor    %esi,%esi
mov    %r14,%rdi
call   1040 <create_new_file@plt>
test   %rax,%rax
je     11fc <main+0x9c>
lea    0xea5(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   1060 <remove_files_maybe@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e13(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xe46(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe40(%rip),%rsi
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"Usage: %s /path/filename number_to_queue [mode]\0A\00"
@.str.1 = [26 x i8] c"Note: mode must be octal\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [45 x i8] c"ERROR: %s cannot create next file for (%s).\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %10
br label %22
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %9
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %14
store i32 1, i32* %10
br label %21
21: ; preds = %20, %14
br label %22
22: ; preds = %21, %13
%23 = load i32, i32* %10
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %22
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
store i8* %37, i8** %6
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 4
br i1 %39, label %40, label %44
40: ; preds = %34
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
store i8* %43, i8** %8
br label %44
44: ; preds = %40, %34
%45 = load i8*, i8** %6
%46 = load i8*, i8** %8
%47 = call i8* @create_new_file(i8* %45, i8* %46)
store i8* %47, i8** %7
%48 = load i8*, i8** %7
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %56
50: ; preds = %44
%51 = load i8*, i8** %7
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i8*, i8** %6
%54 = load i32, i32* %9
%55 = call i32 @remove_files_maybe(i8* %53, i32 %54)
ret i32 0
56: ; preds = %44
%57 = load i32, i32* @stderr
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 0
%60 = load i8*, i8** %59
%61 = load i8*, i8** %6
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %60, i8* %61)
%63 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"Usage: %s /path/filename number_to_queue [mode]\0A\00"
@.str.1 = [26 x i8] c"Note: mode must be octal\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [45 x i8] c"ERROR: %s cannot create next file for (%s).\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 2
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %2, %4
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %4
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = icmp eq i32 %0, 4
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
br label %23
23: ; preds = %20, %16
%24 = phi i8* [ %22, %20 ], [ null, %16 ]
%25 = tail call i8* @create_new_file(i8* %18, i8* %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%29 = tail call i32 @remove_files_maybe(i8* %18, i32 %7)
ret i32 0
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %1
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %32, i8* %18)
%34 = tail call i32 @exit(i32 1)
unreachable
}