#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*/ map_char(char **, unsigned char);
int /*<<< orphan*/ printf(char *, unsigned char *, ...);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(unsigned char *, unsigned char *);
int strlen(int /*<<< orphan*/);
unsigned char *strrchr(unsigned char *, char);
void format(char *buf, char **map) {
  unsigned char outstring[128] = "";
  unsigned char *sp = buf, *dp;
  int table = 0;
  while (*sp) {
    if (*sp == 7 && table) {
      printf("%s%s", outstring, map_char(map, '\n'));
      outstring[0] = 0;
      table = 0;
      sp++;
    } else {
      if (strlen(strcat(outstring, map_char(map, *sp))) > 72) {
        dp = strrchr(outstring, ' ');
        if (dp) {
          *(dp++) = 0;
          printf("%s\n", outstring);
          strcpy(outstring, dp);
        } else {
          int i;
          for (i = 0; i < 72; i++)
            putc(outstring[i], stdout);
          putc('\n', stdout);
          strcpy(outstring, outstring + 72);
        }
      }
      table = *(sp++) == 7;
    }
  }
  if (outstring[0] == 0)
    putc('\n', stdout);
  else
    printf("%s\n\n", outstring);
}


x86 assembly (clang, -O0):
<format>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x98(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    -0x98(%rbp),%rax
cmpb   $0x0,(%rax)
je     1397 <format+0x217>
mov    -0x98(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7,%eax
jne    1246 <format+0xc6>
cmpl   $0x0,-0xa4(%rbp)
je     1246 <format+0xc6>
lea    -0x90(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <map_char@plt>
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movb   $0x0,-0x90(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
jmp    1392 <format+0x212>
lea    -0x90(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x98(%rbp),%rax
movzbl (%rax),%esi
call   1040 <map_char@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%esi
call   10a0 <strcat@plt>
mov    %eax,%edi
call   1050 <strlen@plt>
cmp    $0x48,%eax
jle    1369 <format+0x1e9>
lea    -0x90(%rbp),%rdi
mov    $0x20,%esi
call   1070 <strrchr@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
je     12f0 <format+0x170>
mov    -0xa0(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0xa0(%rbp)
movb   $0x0,(%rax)
lea    -0x90(%rbp),%rsi
lea    0xd34(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1364 <format+0x1e4>
movl   $0x0,-0xa8(%rbp)
cmpl   $0x48,-0xa8(%rbp)
jge    133a <format+0x1ba>
movslq -0xa8(%rbp),%rax
mov    -0x90(%rbp,%rax,1),%al
mov    0x2cc4(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1090 <putc@plt>
mov    -0xa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa8(%rbp)
jmp    12fa <format+0x17a>
mov    0x2c9f(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
lea    -0x90(%rbp),%rdi
lea    -0x90(%rbp),%rsi
add    $0x48,%rsi
call   1030 <strcpy@plt>
jmp    1369 <format+0x1e9>
mov    -0x98(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x98(%rbp)
movzbl (%rax),%eax
cmp    $0x7,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xa4(%rbp)
jmp    11bb <format+0x3b>
movzbl -0x90(%rbp),%eax
cmp    $0x0,%eax
jne    13bf <format+0x23f>
mov    0x2c32(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1090 <putc@plt>
jmp    13d4 <format+0x254>
lea    -0x90(%rbp),%rsi
lea    0xc3c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    (%rdi),%al
test   %al,%al
je     12c8 <format+0x158>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe3e(%rip),%r15
mov    %rsp,%r12
mov    0x2e14(%rip),%r13
xor    %ebp,%ebp
jmp    120e <format+0x9e>
mov    %rax,%rbp
add    $0x1,%rbp
movb   $0x0,(%rax)
lea    0xe24(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
xor    %ebp,%ebp
cmpb   $0x7,(%rbx)
sete   %bpl
mov    0x1(%rbx),%al
add    $0x1,%rbx
test   %al,%al
je     12af <format+0x13f>
cmp    $0x7,%al
jne    1240 <format+0xd0>
test   %ebp,%ebp
je     1240 <format+0xd0>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <map_char@plt>
xor    %ebp,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
movb   $0x0,(%rsp)
jmp    11ff <format+0x8f>
nopw   0x0(%rax,%rax,1)
movzbl %al,%esi
mov    %r14,%rdi
call   1040 <map_char@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1090 <strcat@plt>
mov    %eax,%edi
call   1050 <strlen@plt>
cmp    $0x49,%eax
jl     11f6 <format+0x86>
mov    %r12,%rdi
mov    $0x20,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
jne    11d0 <format+0x60>
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl (%rsp,%rbp,1),%edi
mov    0x0(%r13),%esi
call   1080 <putc@plt>
add    $0x1,%rbp
cmp    $0x48,%rbp
jne    1280 <format+0x110>
mov    0x0(%r13),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
lea    0x48(%rsp),%rbp
jmp    11eb <format+0x7b>
cmpb   $0x0,(%rsp)
je     12c8 <format+0x158>
lea    0xd4d(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12db <format+0x16b>
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
@.str.2 = [5 x i8] c"%s\0A\0A\00"
define void @format(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca [128 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%10 = bitcast [128 x i8]* %5 to i8*
%11 = load i8*, i8** %3
store i8* %11, i8** %6
store i32 0, i32* %8
br label %12
12: ; preds = %83, %2
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %84
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 7
br i1 %20, label %21, label %32
21: ; preds = %16
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %21
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%26 = load i8**, i8*** %4
%27 = call i32 @map_char(i8** %26, i8 zeroext 10)
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %27)
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
store i8 0, i8* %29
store i32 0, i32* %8
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
br label %83
32: ; preds = %21, %16
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%34 = load i8**, i8*** %4
%35 = load i8*, i8** %6
%36 = load i8, i8* %35
%37 = call i32 @map_char(i8** %34, i8 zeroext %36)
%38 = call i32 @strcat(i8* %33, i32 %37)
%39 = call i32 @strlen(i32 %38)
%40 = icmp sgt i32 %39, 72
br i1 %40, label %41, label %76
41: ; preds = %32
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%43 = call i8* @strrchr(i8* %42, i8 signext 32)
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %54
46: ; preds = %41
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %7
store i8 0, i8* %47
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%50 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %49)
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%52 = load i8*, i8** %7
%53 = call i32 @strcpy(i8* %51, i8* %52)
br label %75
54: ; preds = %41
store i32 0, i32* %9
br label %55
55: ; preds = %65, %54
%56 = load i32, i32* %9
%57 = icmp slt i32 %56, 72
br i1 %57, label %58, label %68
58: ; preds = %55
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = load i32, i32* @stdout
%64 = call i32 @putc(i8 signext %62, i32 %63)
br label %65
65: ; preds = %58
%66 = load i32, i32* %9
%67 = add nsw i32 %66, 1
store i32 %67, i32* %9
br label %55
68: ; preds = %55
%69 = load i32, i32* @stdout
%70 = call i32 @putc(i8 signext 10, i32 %69)
%71 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%72 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%73 = getelementptr inbounds i8, i8* %72, i64 72
%74 = call i32 @strcpy(i8* %71, i8* %73)
br label %75
75: ; preds = %68, %46
br label %76
76: ; preds = %75, %32
%77 = load i8*, i8** %6
%78 = getelementptr inbounds i8, i8* %77, i32 1
store i8* %78, i8** %6
%79 = load i8, i8* %77
%80 = zext i8 %79 to i32
%81 = icmp eq i32 %80, 7
%82 = zext i1 %81 to i32
store i32 %82, i32* %8
br label %83
83: ; preds = %76, %24
br label %12
84: ; preds = %12
%85 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = icmp eq i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %84
%90 = load i32, i32* @stdout
%91 = call i32 @putc(i8 signext 10, i32 %90)
br label %95
92: ; preds = %84
%93 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%94 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %93)
br label %95
95: ; preds = %92, %89
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
@.str.2 = [5 x i8] c"%s\0A\0A\00"
define void @format(i8* nocapture %0, i8** %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %56, label %7
7: ; preds = %2
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 72
br label %9
9: ; preds = %7, %48
%10 = phi i8 [ %5, %7 ], [ %51, %48 ]
%11 = phi i32 [ 0, %7 ], [ %49, %48 ]
%12 = phi i8* [ %0, %7 ], [ %50, %48 ]
%13 = icmp eq i8 %10, 7
%14 = icmp ne i32 %11, 0
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = call i32 @map_char(i8** %1, i8 zeroext 10)
%18 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %17)
store i8 0, i8* %4
br label %48
19: ; preds = %9
%20 = call i32 @map_char(i8** %1, i8 zeroext %10)
%21 = call i32 @strcat(i8* %4, i32 %20)
%22 = call i32 @strlen(i32 %21)
%23 = icmp sgt i32 %22, 72
br i1 %23, label %24, label %44
24: ; preds = %19
%25 = call i8* @strrchr(i8* %4, i8 signext 32)
%26 = icmp eq i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = getelementptr inbounds i8, i8* %25, i64 1
store i8 0, i8* %25
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %41
30: ; preds = %24, %30
%31 = phi i64 [ %36, %30 ], [ 0, %24 ]
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = load i32, i32* @stdout
%35 = call i32 @putc(i8 signext %33, i32 %34)
%36 = add nuw nsw i64 %31, 1
%37 = icmp eq i64 %36, 72
br i1 %37, label %38, label %30
38: ; preds = %30
%39 = load i32, i32* @stdout
%40 = call i32 @putc(i8 signext 10, i32 %39)
br label %41
41: ; preds = %38, %27
%42 = phi i8* [ %28, %27 ], [ %8, %38 ]
%43 = call i32 @strcpy(i8* %4, i8* %42)
br label %44
44: ; preds = %41, %19
%45 = load i8, i8* %12
%46 = icmp eq i8 %45, 7
%47 = zext i1 %46 to i32
br label %48
48: ; preds = %44, %16
%49 = phi i32 [ 0, %16 ], [ %47, %44 ]
%50 = getelementptr inbounds i8, i8* %12, i64 1
%51 = load i8, i8* %50
%52 = icmp eq i8 %51, 0
br i1 %52, label %53, label %9
53: ; preds = %48
%54 = load i8, i8* %4
%55 = icmp eq i8 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %2, %53
%57 = load i32, i32* @stdout
%58 = call i32 @putc(i8 signext 10, i32 %57)
br label %61
59: ; preds = %53
%60 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %61
61: ; preds = %59, %56
ret void
}