#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*/ cio_seek(int);
int /*<<< orphan*/ cio_skip(int);
int cio_tell();
int /*<<< orphan*/ cio_write(int, int);
int /*<<< orphan*/ sprintf(char *, char *);
unsigned int strlen(char *);
void j2k_write_com() {
  unsigned int i;
  int lenp, len;
  char str[256];
  sprintf(str, "Creator: J2000 codec");

  cio_write(0xff64, 2);
  lenp = cio_tell();
  cio_skip(2);
  cio_write(0, 2);
  for (i = 0; i < strlen(str); i++) {
    cio_write(str[i], 1);
  }
  len = cio_tell() - lenp;
  cio_seek(lenp);
  cio_write(len, 2);
  cio_seek(lenp + len);
}


x86 assembly (clang, -O0):
<j2k_write_com>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1080 <sprintf@plt>
mov    $0xff64,%edi
mov    $0x2,%esi
call   1060 <cio_write@plt>
mov    $0x0,%al
call   1070 <cio_tell@plt>
mov    %eax,-0x8(%rbp)
mov    $0x2,%edi
call   1030 <cio_skip@plt>
xor    %edi,%edi
mov    $0x2,%esi
call   1060 <cio_write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x114(%rbp),%eax
cmp    %ecx,%eax
jae    11fc <j2k_write_com+0x9c>
mov    -0x4(%rbp),%eax
movsbl -0x110(%rbp,%rax,1),%edi
ff
mov    $0x1,%esi
call   1060 <cio_write@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <j2k_write_com+0x54>
mov    $0x0,%al
call   1070 <cio_tell@plt>
sub    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <cio_seek@plt>
mov    -0xc(%rbp),%edi
mov    $0x2,%esi
call   1060 <cio_write@plt>
mov    -0x8(%rbp),%edi
add    -0xc(%rbp),%edi
call   1050 <cio_seek@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<j2k_write_com>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
movups 0xe9e(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x6365646f632030,%rax
mov    %rax,0xd(%rsp)
mov    $0xff64,%edi
mov    $0x2,%esi
call   1060 <cio_write@plt>
xor    %eax,%eax
call   1070 <cio_tell@plt>
mov    %eax,%r14d
mov    $0x2,%edi
call   1030 <cio_skip@plt>
xor    %edi,%edi
mov    $0x2,%esi
call   1060 <cio_write@plt>
mov    %rsp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11e1 <j2k_write_com+0x91>
xor    %ebp,%ebp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%rsp,%rbp,1),%edi
mov    $0x1,%esi
call   1060 <cio_write@plt>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jb     11c0 <j2k_write_com+0x70>
xor    %eax,%eax
call   1070 <cio_tell@plt>
mov    %eax,%ebp
mov    %eax,%ebx
sub    %r14d,%ebx
mov    %r14d,%edi
call   1050 <cio_seek@plt>
mov    %ebx,%edi
mov    $0x2,%esi
call   1060 <cio_write@plt>
mov    %ebp,%edi
call   1050 <cio_seek@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Creator: J2000 codec\00"
define void @j2k_write_com() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @cio_write(i32 65380, i32 2)
%8 = call i32 (...) @cio_tell()
store i32 %8, i32* %2
%9 = call i32 @cio_skip(i32 2)
%10 = call i32 @cio_write(i32 0, i32 2)
store i32 0, i32* %1
br label %11
11: ; preds = %23, %0
%12 = load i32, i32* %1
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = icmp ult i32 %12, %14
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = load i32, i32* %1
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = call i32 @cio_write(i32 %21, i32 1)
br label %23
23: ; preds = %16
%24 = load i32, i32* %1
%25 = add i32 %24, 1
store i32 %25, i32* %1
br label %11
26: ; preds = %11
%27 = call i32 (...) @cio_tell()
%28 = load i32, i32* %2
%29 = sub nsw i32 %27, %28
store i32 %29, i32* %3
%30 = load i32, i32* %2
%31 = call i32 @cio_seek(i32 %30)
%32 = load i32, i32* %3
%33 = call i32 @cio_write(i32 %32, i32 2)
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = add nsw i32 %34, %35
%37 = call i32 @cio_seek(i32 %36)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"Creator: J2000 codec\00"
define void @j2k_write_com() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @cio_write(i32 65380, i32 2)
%4 = tail call i32 (...) @cio_tell()
%5 = tail call i32 @cio_skip(i32 2)
%6 = tail call i32 @cio_write(i32 0, i32 2)
%7 = call i32 @strlen(i8* %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %0, %9
%10 = phi i64 [ %15, %9 ], [ 0, %0 ]
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = call i32 @cio_write(i32 %13, i32 1)
%15 = add nuw nsw i64 %10, 1
%16 = call i32 @strlen(i8* %2)
%17 = zext i32 %16 to i64
%18 = icmp ult i64 %15, %17
br i1 %18, label %9, label %19
19: ; preds = %9, %0
%20 = call i32 (...) @cio_tell()
%21 = sub nsw i32 %20, %4
%22 = call i32 @cio_seek(i32 %4)
%23 = call i32 @cio_write(i32 %21, i32 2)
%24 = call i32 @cio_seek(i32 %20)
ret void
}