#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ showperms(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char **argv) {
  if (argc == 1) {
    char buf[1025];
    while (fgets(buf, 1024, stdin)) {
      buf[strlen(buf) - 1] = 0;
      showperms(buf);
    }
  } else {
    for (argv++; *argv; argv++)
      showperms(*argv);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ab <main+0x7b>
jmp    1158 <main+0x28>
lea    -0x420(%rbp),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11a6 <main+0x76>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
call   1030 <showperms@plt>
jmp    1158 <main+0x28>
jmp    11e7 <main+0xb7>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     11e2 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <showperms@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <main+0x87>
jmp    11e7 <main+0xb7>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x1,%edi
jne    117e <main+0x4e>
mov    0x2ea2(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11a1 <main+0x71>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1030 <showperms@plt>
mov    (%r14),%edx
jmp    1150 <main+0x20>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     11a1 <main+0x71>
add    $0x10,%rbx
xchg   %ax,%ax
call   1030 <showperms@plt>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1190 <main+0x60>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1025 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %24
9: ; preds = %2
br label %10
10: ; preds = %15, %9
%11 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i64 @fgets(i8* %11, i32 1024, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 %19
store i8 0, i8* %20
%21 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%22 = call i32 @showperms(i8* %21)
br label %10
23: ; preds = %10
br label %39
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i32 1
store i8** %26, i8*** %5
br label %27
27: ; preds = %35, %24
%28 = load i8**, i8*** %5
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %38
31: ; preds = %27
%32 = load i8**, i8*** %5
%33 = load i8*, i8** %32
%34 = call i32 @showperms(i8* %33)
br label %35
35: ; preds = %31
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i32 1
store i8** %37, i8*** %5
br label %27
38: ; preds = %27
br label %39
39: ; preds = %38, %23
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1025 x i8]
%4 = icmp eq i32 %0, 1
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %31, label %24
9: ; preds = %2
%10 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i64 @fgets(i8* %10, i32 1024, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %9, %14
%15 = call i32 @strlen(i8* %10)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @showperms(i8* %10)
%20 = load i32, i32* @stdin
%21 = call i64 @fgets(i8* %10, i32 1024, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %14
23: ; preds = %14, %9
br label %31
24: ; preds = %5, %24
%25 = phi i8* [ %29, %24 ], [ %7, %5 ]
%26 = phi i8** [ %28, %24 ], [ %6, %5 ]
%27 = tail call i32 @showperms(i8* %25)
%28 = getelementptr inbounds i8*, i8** %26, i64 1
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %24
31: ; preds = %24, %5, %23
ret i32 0
}