#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 */
size_t fwrite(char *, int, int, int /*<<< orphan*/ *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
size_t fwrite_str80(char *str, FILE *fp) {
  char cbuf[80];
  size_t len;
  int i;
  len = strlen(str);
  strncpy(cbuf, str, len < 80 ? len : 80);
  for (i = len; i < 80; i++)
    cbuf[i] = '\0';
  return fwrite(cbuf, sizeof(char), 80, fp);
}


x86 assembly (clang, -O0):
<fwrite_str80>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
cmpq   $0x50,-0x68(%rbp)
jae    117b <fwrite_str80+0x4b>
mov    -0x68(%rbp),%rax
mov    %rax,-0x88(%rbp)
jmp    118c <fwrite_str80+0x5c>
mov    $0x50,%eax
mov    %rax,-0x88(%rbp)
jmp    118c <fwrite_str80+0x5c>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x68(%rbp),%rax
mov    %eax,-0x6c(%rbp)
cmpl   $0x50,-0x6c(%rbp)
jge    11c8 <fwrite_str80+0x98>
movslq -0x6c(%rbp),%rax
movb   $0x0,-0x60(%rbp,%rax,1)
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    11a7 <fwrite_str80+0x77>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x50,%edx
call   1050 <fwrite@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwrite_str80>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
cmp    $0x50,%rax
mov    $0x50,%edx
cmovb  %rax,%rdx
mov    %rsp,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
cmp    $0x4f,%ebx
jg     118d <fwrite_str80+0x4d>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rdi
mov    $0x4f,%edx
sub    %eax,%edx
add    $0x1,%rdx
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x50,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @fwrite_str80(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [80 x i8]
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %6
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = load i64, i64* %6
%13 = icmp ult i64 %12, 80
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i64, i64* %6
br label %17
16: ; preds = %2
br label %17
17: ; preds = %16, %14
%18 = phi i64 [ %15, %14 ], [ 80, %16 ]
%19 = call i32 @strncpy(i8* %10, i8* %11, i64 %18)
%20 = load i64, i64* %6
%21 = trunc i64 %20 to i32
store i32 %21, i32* %7
br label %22
22: ; preds = %29, %17
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 80
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %25
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %22
32: ; preds = %22
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%34 = load i32*, i32** %4
%35 = call i64 @fwrite(i8* %33, i32 1, i32 80, i32* %34)
ret i64 %35
}

LLVM IR (-O2):
define i64 @fwrite_str80(i8* %0, i32* nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = icmp ult i64 %5, 80
%7 = select i1 %6, i64 %5, i64 80
%8 = call i32 @strncpy(i8* %4, i8* %0, i64 %7)
%9 = trunc i64 %5 to i32
%10 = icmp slt i32 %9, 80
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = shl i64 %5, 32
%13 = ashr exact i64 %12, 32
%14 = getelementptr [80 x i8], [80 x i8]* %3, i64 0, i64 %13
%15 = sub i64 79, %5
%16 = and i64 %15, 4294967295
%17 = add nuw nsw i64 %16, 1
br label %18
18: ; preds = %11, %2
%19 = call i64 @fwrite(i8* %4, i32 1, i32 80, i32* %1)
ret i64 %19
}