#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
void genciphertext(int *buf, int lens, char *name) {
  FILE *fd;
  int head = 0xffff;
  fd = fopen(name, "wb");
  fwrite(&head, 4, 1, fd);
  for (int i = 0; i < lens; i++) {
    fwrite(&buf[i], 4, 1, fd);
  }
  fclose(fd);
}


x86 assembly (clang, -O0):
<genciphertext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffff,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
lea    -0x24(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b8 <genciphertext+0x88>
mov    -0x8(%rbp),%rdi
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117c <genciphertext+0x4c>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genciphertext>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
movl   $0xffff,0xc(%rsp)
lea    0xeb4(%rip),%rsi
mov    %rdx,%rdi
call   1040 <fopen@plt>
mov    %rax,%r14
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
test   %ebp,%ebp
jle    119f <genciphertext+0x6f>
mov    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <fwrite@plt>
add    $0x4,%rbx
add    $0xffffffffffffffff,%rbp
jne    1180 <genciphertext+0x50>
mov    %r14,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define void @genciphertext(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 65535, i32* %8
%10 = load i8*, i8** %6
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = call i32 @fwrite(i32* %8, i32 4, i32 1, i32* %12)
store i32 0, i32* %9
br label %14
14: ; preds = %25, %3
%15 = load i32, i32* %9
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = load i32*, i32** %4
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32*, i32** %7
%24 = call i32 @fwrite(i32* %22, i32 4, i32 1, i32* %23)
br label %25
25: ; preds = %18
%26 = load i32, i32* %9
%27 = add nsw i32 %26, 1
store i32 %27, i32* %9
br label %14
28: ; preds = %14
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
ret void
}

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