#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 */
struct multicol {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ multicol_end(struct multicol *);
int /*<<< orphan*/ multicol_pprint(struct multicol *, int, int, int);
struct multicol *multicol_start(int);
int /*<<< orphan*/ multicol_store(struct multicol *, char const *);
scalar_t__ strlen(char const *);
int display_directory(int p, const char *buff, int cnt) {
  const char *s = buff;
  struct multicol *m = multicol_start(800);
  int i;
  for (i = 0; (i < cnt && i < 800); i++) {
    multicol_store(m, s);
    s += strlen(s) + 1;
  }
  multicol_pprint(m, p, 78, 1);
  multicol_end(m);
  return i;
}


x86 assembly (clang, -O0):
<display_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x320,%edi
call   1050 <multicol_start@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x2d(%rbp)
jge    119d <display_directory+0x4d>
cmpl   $0x320,-0x2c(%rbp)
setl   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11ad <display_directory+0x5d>
jmp    11dd <display_directory+0x8d>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <multicol_store@plt>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117f <display_directory+0x2f>
mov    -0x28(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    $0x4e,%edx
mov    $0x1,%ecx
call   1070 <multicol_pprint@plt>
mov    -0x28(%rbp),%rdi
call   1030 <multicol_end@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_directory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %edi,%r14d
mov    $0x320,%edi
call   1050 <multicol_start@plt>
mov    %rax,%r13
test   %r12d,%r12d
jle    11c1 <display_directory+0x71>
add    $0xffffffff,%r12d
cmp    $0x31f,%r12d
mov    $0x31f,%r15d
cmovb  %r12d,%r15d
add    $0x1,%r15d
mov    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <multicol_store@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    %rax,%rbp
add    $0x1,%rbp
add    $0xffffffff,%ebx
jne    11a0 <display_directory+0x50>
jmp    11c4 <display_directory+0x74>
xor    %r15d,%r15d
mov    %r13,%rdi
mov    %r14d,%esi
mov    $0x4e,%edx
mov    $0x1,%ecx
call   1070 <multicol_pprint@plt>
mov    %r13,%rdi
call   1030 <multicol_end@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.multicol = type { i32 }
define i32 @display_directory(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.multicol*
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
store i8* %10, i8** %7
%11 = call %struct.multicol* @multicol_start(i32 800)
store %struct.multicol* %11, %struct.multicol** %8
store i32 0, i32* %9
br label %12
12: ; preds = %30, %3
%13 = load i32, i32* %9
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 800
br label %19
19: ; preds = %16, %12
%20 = phi i1 [ false, %12 ], [ %18, %16 ]
br i1 %20, label %21, label %33
21: ; preds = %19
%22 = load %struct.multicol*, %struct.multicol** %8
%23 = load i8*, i8** %7
%24 = call i32 @multicol_store(%struct.multicol* %22, i8* %23)
%25 = load i8*, i8** %7
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 %27
store i8* %29, i8** %7
br label %30
30: ; preds = %21
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %12
33: ; preds = %19
%34 = load %struct.multicol*, %struct.multicol** %8
%35 = load i32, i32* %4
%36 = call i32 @multicol_pprint(%struct.multicol* %34, i32 %35, i32 78, i32 1)
%37 = load %struct.multicol*, %struct.multicol** %8
%38 = call i32 @multicol_end(%struct.multicol* %37)
%39 = load i32, i32* %9
ret i32 %39
}

LLVM IR (-O2):
%struct.multicol = type { i32 }
define i32 @display_directory(i32 %0, i8* %1, i32 %2) {
%4 = tail call %struct.multicol* @multicol_start(i32 800)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %19
6: ; preds = %3
%7 = add nsw i32 %2, -1
%8 = call i32 @llvm.umin.i32(i32 %7, i32 799)
%9 = add nuw nsw i32 %8, 1
br label %10
10: ; preds = %6, %10
%11 = phi i32 [ %17, %10 ], [ 0, %6 ]
%12 = phi i8* [ %16, %10 ], [ %1, %6 ]
%13 = tail call i32 @multicol_store(%struct.multicol* %4, i8* %12)
%14 = tail call i64 @strlen(i8* dereferenceable(1) %12)
%15 = add nsw i64 %14, 1
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = add nuw nsw i32 %11, 1
%18 = icmp eq i32 %11, %8
br i1 %18, label %19, label %10
19: ; preds = %10, %3
%20 = phi i32 [ 0, %3 ], [ %9, %10 ]
%21 = tail call i32 @multicol_pprint(%struct.multicol* %4, i32 %0, i32 78, i32 1)
%22 = tail call i32 @multicol_end(%struct.multicol* %4)
ret i32 %20
}