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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int strlen(char *);
void fprintnf(FILE *fp, char *str, int n) {
  int i, l, m;
  l = strlen(str);
  m = n < l ? n : l;
  for (i = 0; i < m; i++)
    fprintf(fp, "%c", str[i]);
  if (m < l)
    fprintf(fp, "...");
}


x86 assembly (clang, -O0):
<fprintnf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1156 <fprintnf+0x36>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    115c <fprintnf+0x3c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11a1 <fprintnf+0x81>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1169 <fprintnf+0x49>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11bf <fprintnf+0x9f>
mov    -0x8(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprintnf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
cmp    %r14d,%eax
cmovg  %r14d,%eax
test   %eax,%eax
jle    1177 <fprintnf+0x47>
mov    %eax,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl 0x0(%r13,%rbp,1),%edi
mov    %r12,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <fprintnf+0x30>
cmp    %r14d,%r15d
jle    11a3 <fprintnf+0x73>
lea    0xe7d(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r12,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fwrite@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [4 x i8] c"...\00"
define void @fprintnf(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %8
%12 = load i32, i32* %6
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %6
br label %19
17: ; preds = %3
%18 = load i32, i32* %8
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ %16, %15 ], [ %18, %17 ]
store i32 %20, i32* %9
store i32 0, i32* %7
br label %21
21: ; preds = %34, %19
%22 = load i32, i32* %7
%23 = load i32, i32* %9
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = load i32*, i32** %4
%27 = load i8*, i8** %5
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %25
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %21
37: ; preds = %21
%38 = load i32, i32* %9
%39 = load i32, i32* %8
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32*, i32** %4
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %41, %37
ret void
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"...\00"
define void @fprintnf(i32* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = icmp sgt i32 %4, %2
%6 = select i1 %5, i32 %2, i32 %4
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %3
%9 = zext i32 %6 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %16, %10 ]
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = tail call i32 @fputc(i32 %14, i32* %0)
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %9
br i1 %17, label %18, label %10
18: ; preds = %10, %3
br i1 %5, label %19, label %21
19: ; preds = %18
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 3, i64 1, i32* %0)
br label %21
21: ; preds = %19, %18
ret void
}