#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 *, char *);
unsigned int strlen(char *);
void jp2_write_url(char *Idx_file) {
  int len, lenp;
  unsigned int i;
  char str[256];
  sprintf(str, "%s", Idx_file);
  lenp = cio_tell();
  cio_skip(4);
  cio_write(0x75726c20, 4);
  cio_write(0, 1);
  cio_write(0, 3);
  for (i = 0; i < strlen(str); i++) {
    cio_write(str[i], 1);
  }
  len = cio_tell() - lenp;
  cio_seek(lenp);
  cio_write(len, 4);
  cio_seek(lenp + len);
}


x86 assembly (clang, -O0):
<jp2_write_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe7f(%rip),%rsi
call   1080 <sprintf@plt>
mov    $0x0,%al
call   1070 <cio_tell@plt>
mov    %eax,-0x10(%rbp)
mov    $0x4,%edi
call   1030 <cio_skip@plt>
mov    $0x75726c20,%edi
mov    $0x4,%esi
call   1060 <cio_write@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <cio_write@plt>
xor    %edi,%edi
mov    $0x3,%esi
call   1060 <cio_write@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x124(%rbp),%eax
cmp    %ecx,%eax
jae    1210 <jp2_write_url+0xb0>
mov    -0x14(%rbp),%eax
movsbl -0x120(%rbp,%rax,1),%edi
ff
mov    $0x1,%esi
call   1060 <cio_write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c8 <jp2_write_url+0x68>
mov    $0x0,%al
call   1070 <cio_tell@plt>
sub    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <cio_seek@plt>
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
call   1060 <cio_write@plt>
mov    -0x10(%rbp),%edi
add    -0xc(%rbp),%edi
call   1050 <cio_seek@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jp2_write_url>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strcpy@plt>
xor    %eax,%eax
call   1080 <cio_tell@plt>
mov    %eax,%r15d
mov    $0x4,%edi
call   1030 <cio_skip@plt>
mov    $0x75726c20,%edi
mov    $0x4,%esi
call   1070 <cio_write@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1070 <cio_write@plt>
xor    %edi,%edi
mov    $0x3,%esi
call   1070 <cio_write@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     11f1 <jp2_write_url+0x91>
xor    %ebp,%ebp
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
movsbl (%rsp,%rbp,1),%edi
mov    $0x1,%esi
call   1070 <cio_write@plt>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jb     11d0 <jp2_write_url+0x70>
xor    %eax,%eax
call   1080 <cio_tell@plt>
mov    %eax,%ebp
mov    %eax,%ebx
sub    %r15d,%ebx
mov    %r15d,%edi
call   1060 <cio_seek@plt>
mov    %ebx,%edi
mov    $0x4,%esi
call   1070 <cio_write@plt>
mov    %ebp,%edi
call   1060 <cio_seek@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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