#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ indent_spaces(char *, int);
int /*<<< orphan*/ indent_tabs(char *, int);
int /*<<< orphan*/ msg(char *, char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ trim_back(char *);
void retab(FILE *fp, int flags) {
  int use_tabs = ((1 << 17) & flags) ? 1 : 0;
  int trim_right = ((1 << 16) & flags) ? 1 : 0;
  int indent_size = 0xFFFF & flags;
  ssize_t n = 0;
  char *line;
  size_t len;
  msg("fp         %08X", (void *)fp);
  msg("indent     %d", indent_size);
  msg("use tabs   %c", use_tabs ? 'Y' : 'N');
  msg("trim right %c", trim_right ? 'Y' : 'N');
  for (;;) {
    n = getline(&line, &len, fp);
    if (n <= 0)
      break;
    if (trim_right)
      trim_back(line);
    if (use_tabs)
      indent_tabs(line, indent_size);
    else
      indent_spaces(line, indent_size);
    puts(line);
  }
}


x86 assembly (clang, -O0):
<retab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edx
and    $0x20000,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edx
and    $0x10000,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
and    $0xffff,%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
lea    0xe41(%rip),%rdi
movsbl %al,%esi
call   1080 <msg@plt>
mov    -0x18(%rbp),%eax
lea    0xe3f(%rip),%rdi
movsbl %al,%esi
call   1080 <msg@plt>
mov    -0x10(%rbp),%edx
mov    $0x4e,%eax
mov    $0x59,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
lea    0xe2b(%rip),%rdi
movsbl %al,%esi
call   1080 <msg@plt>
mov    -0x14(%rbp),%edx
mov    $0x4e,%eax
mov    $0x59,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
lea    0xe17(%rip),%rdi
movsbl %al,%esi
call   1080 <msg@plt>
mov    -0x8(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <getline@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jg     1242 <retab+0xe2>
jmp    128a <retab+0x12a>
cmpl   $0x0,-0x14(%rbp)
je     1255 <retab+0xf5>
mov    -0x28(%rbp),%rdi
call   1040 <trim_back@plt>
cmpl   $0x0,-0x10(%rbp)
je     1270 <retab+0x110>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <indent_tabs@plt>
jmp    127c <retab+0x11c>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <indent_spaces@plt>
mov    -0x28(%rbp),%rdi
call   1030 <puts@plt>
jmp    121d <retab+0xbd>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<retab>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
movsbl %r14b,%esi
lea    0xe84(%rip),%rdi
call   1080 <msg@plt>
movsbl %bl,%esi
lea    0xe85(%rip),%rdi
call   1080 <msg@plt>
test   $0x20000,%ebx
mov    $0x4e,%r15d
mov    $0x59,%ebp
mov    $0x59,%esi
cmove  %r15d,%esi
lea    0xe6d(%rip),%rdi
call   1080 <msg@plt>
test   $0x10000,%ebx
cmove  %r15d,%ebp
lea    0xe65(%rip),%rdi
mov    %ebp,%esi
call   1080 <msg@plt>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %r14,%rdx
call   1070 <getline@plt>
test   %rax,%rax
jle    1237 <retab+0xd7>
movzwl %bx,%ebp
mov    %rsp,%r15
lea    0x8(%rsp),%r12
jmp    1211 <retab+0xb1>
call   1050 <indent_spaces@plt>
mov    (%rsp),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1070 <getline@plt>
test   %rax,%rax
jle    1237 <retab+0xd7>
test   $0x10000,%ebx
je     1222 <retab+0xc2>
mov    (%rsp),%rdi
call   1040 <trim_back@plt>
mov    (%rsp),%rdi
mov    %ebp,%esi
test   $0x20000,%ebx
je     11f0 <retab+0x90>
call   1060 <indent_tabs@plt>
jmp    11f5 <retab+0x95>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"fp %08X\00"
@.str.1 = [14 x i8] c"indent %d\00"
@.str.2 = [14 x i8] c"use tabs %c\00"
@.str.3 = [14 x i8] c"trim right %c\00"
define void @retab(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i32* %0, i32** %3
store i32 %1, i32* %4
%11 = load i32, i32* %4
%12 = and i32 131072, %11
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 1, i32 0
store i32 %15, i32* %5
%16 = load i32, i32* %4
%17 = and i32 65536, %16
%18 = icmp ne i32 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 1, i32 0
store i32 %20, i32* %6
%21 = load i32, i32* %4
%22 = and i32 65535, %21
store i32 %22, i32* %7
store i64 0, i64* %8
%23 = load i32*, i32** %3
%24 = bitcast i32* %23 to i8*
%25 = ptrtoint i8* %24 to i8
%26 = call i32 @msg(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext %25)
%27 = load i32, i32* %7
%28 = trunc i32 %27 to i8
%29 = call i32 @msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8 signext %28)
%30 = load i32, i32* %5
%31 = icmp ne i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 89, i32 78
%34 = trunc i32 %33 to i8
%35 = call i32 @msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8 signext %34)
%36 = load i32, i32* %6
%37 = icmp ne i32 %36, 0
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 89, i32 78
%40 = trunc i32 %39 to i8
%41 = call i32 @msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8 signext %40)
br label %42
42: ; preds = %65, %2
%43 = load i32*, i32** %3
%44 = call i64 @getline(i8** %9, i64* %10, i32* %43)
store i64 %44, i64* %8
%45 = load i64, i64* %8
%46 = icmp sle i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %42
br label %68
48: ; preds = %42
%49 = load i32, i32* %6
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i8*, i8** %9
%53 = call i32 @trim_back(i8* %52)
br label %54
54: ; preds = %51, %48
%55 = load i32, i32* %5
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %54
%58 = load i8*, i8** %9
%59 = load i32, i32* %7
%60 = call i32 @indent_tabs(i8* %58, i32 %59)
br label %65
61: ; preds = %54
%62 = load i8*, i8** %9
%63 = load i32, i32* %7
%64 = call i32 @indent_spaces(i8* %62, i32 %63)
br label %65
65: ; preds = %61, %57
%66 = load i8*, i8** %9
%67 = call i32 @puts(i8* %66)
br label %42
68: ; preds = %47
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"fp %08X\00"
@.str.1 = [14 x i8] c"indent %d\00"
@.str.2 = [14 x i8] c"use tabs %c\00"
@.str.3 = [14 x i8] c"trim right %c\00"
define void @retab(i32* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = and i32 %1, 131072
%6 = icmp eq i32 %5, 0
%7 = and i32 %1, 65536
%8 = icmp eq i32 %7, 0
%9 = and i32 %1, 65535
%10 = bitcast i8** %3 to i8*
%11 = bitcast i64* %4 to i8*
%12 = ptrtoint i32* %0 to i64
%13 = trunc i64 %12 to i8
%14 = tail call i32 @msg(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext %13)
%15 = trunc i32 %1 to i8
%16 = tail call i32 @msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8 signext %15)
%17 = select i1 %6, i8 78, i8 89
%18 = tail call i32 @msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8 signext %17)
%19 = select i1 %8, i8 78, i8 89
%20 = tail call i32 @msg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8 signext %19)
%21 = call i64 @getline(i8** %3, i64* %4, i32* %0)
%22 = icmp slt i64 %21, 1
br i1 %22, label %38, label %23
23: ; preds = %2, %33
br i1 %8, label %27, label %24
24: ; preds = %23
%25 = load i8*, i8** %3
%26 = call i32 @trim_back(i8* %25)
br label %27
27: ; preds = %24, %23
%28 = load i8*, i8** %3
br i1 %6, label %31, label %29
29: ; preds = %27
%30 = call i32 @indent_tabs(i8* %28, i32 %9)
br label %33
31: ; preds = %27
%32 = call i32 @indent_spaces(i8* %28, i32 %9)
br label %33
33: ; preds = %31, %29
%34 = load i8*, i8** %3
%35 = call i32 @puts(i8* dereferenceable(1) %34)
%36 = call i64 @getline(i8** %3, i64* %4, i32* %0)
%37 = icmp slt i64 %36, 1
br i1 %37, label %38, label %23
38: ; preds = %33, %2
ret void
}