#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ generate_permutations(char *, size_t);
char *malloc(size_t);
int /*<<< orphan*/ stderr;
size_t strlen(char const *);
char *strncpy(char *, char const *, size_t);
int main(int argc, const char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Exactly one argument is required\n");
    return 1;
  }
  size_t len = strlen(argv[1]);
  char *word = malloc(len + 1);
  word = strncpy(word, argv[1], len);
  generate_permutations(word, len - 1);
  free(word);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a1 <main+0x41>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fd <main+0x9d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <strncpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
call   1080 <generate_permutations@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11ae <main+0x4e>
mov    0x8(%rsi),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <strncpy@plt>
add    $0xffffffffffffffff,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <generate_permutations@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    11c8 <main+0x68>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"Exactly one argument is required\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = add i64 %18, 1
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i64, i64* %6
%26 = call i8* @strncpy(i8* %21, i8* %24, i64 %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = load i64, i64* %6
%29 = sub i64 %28, 1
%30 = call i32 @generate_permutations(i8* %27, i64 %29)
%31 = load i8*, i8** %7
%32 = call i32 @free(i8* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %13, %10
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"Exactly one argument is required\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %17
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strlen(i8* dereferenceable(1) %9)
%11 = add i64 %10, 1
%12 = tail call i8* @malloc(i64 %11)
%13 = tail call i8* @strncpy(i8* dereferenceable(1) %12, i8* %9, i64 %10)
%14 = add i64 %10, -1
%15 = tail call i32 @generate_permutations(i8* %12, i64 %14)
%16 = tail call i32 @free(i8* %12)
br label %17
17: ; preds = %7, %4
%18 = phi i32 [ 1, %4 ], [ 0, %7 ]
ret i32 %18
}