#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 */
unsigned int strnlen(char const *, int);
scalar_t__ unicoder_writeCodePointToFile(int /*<<< orphan*/ *, char const,
                                         unsigned int);
int unicoder_writeCStringToFile(FILE *f, const char *cstr,
                                unsigned int encoding) {
  unsigned int len, i, j, numBytes, returnValue;
  if (f == NULL)
    return -1;
  if (cstr == NULL)
    return -1;
  if (encoding < 1 || 6 < encoding)
    return -2;
  len = strnlen(cstr, 1000005);
  if (len > 1000000)
    return -32;
  for (i = 0, numBytes = 0; i < len; i++)
    numBytes += unicoder_writeCodePointToFile(f, *(cstr + i), encoding);
  return numBytes;
}


x86 assembly (clang, -O0):
<unicoder_writeCStringToFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114a <unicoder_writeCStringToFile+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1202 <unicoder_writeCStringToFile+0xe2>
cmpq   $0x0,-0x18(%rbp)
jne    1161 <unicoder_writeCStringToFile+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    1202 <unicoder_writeCStringToFile+0xe2>
cmpl   $0x1,-0x1c(%rbp)
jb     1179 <unicoder_writeCStringToFile+0x59>
mov    $0x6,%eax
cmp    -0x1c(%rbp),%eax
jae    1185 <unicoder_writeCStringToFile+0x65>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1202 <unicoder_writeCStringToFile+0xe2>
mov    -0x18(%rbp),%rdi
mov    $0xf4245,%esi
call   1040 <strnlen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xf4240,-0x20(%rbp)
jbe    11af <unicoder_writeCStringToFile+0x8f>
movl   $0xffffffe0,-0x4(%rbp)
jmp    1202 <unicoder_writeCStringToFile+0xe2>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    11fc <unicoder_writeCStringToFile+0xdc>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    -0x1c(%rbp),%edx
movsbl %al,%esi
call   1030 <unicoder_writeCodePointToFile@plt>
mov    %rax,%rcx
mov    -0x2c(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11bd <unicoder_writeCStringToFile+0x9d>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unicoder_writeCStringToFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     119f <unicoder_writeCStringToFile+0x7f>
mov    %rsi,%r15
test   %rsi,%rsi
je     119f <unicoder_writeCStringToFile+0x7f>
mov    %edx,%r14d
lea    -0x7(%r14),%eax
mov    $0xfffffffe,%ebp
cmp    $0xfffffffa,%eax
jb     119f <unicoder_writeCStringToFile+0x7f>
mov    %rdi,%r13
mov    %r15,%rdi
mov    $0xf4245,%esi
call   1040 <strnlen@plt>
mov    $0xffffffe0,%ebp
cmp    $0xf4240,%eax
ja     119f <unicoder_writeCStringToFile+0x7f>
test   %eax,%eax
je     119d <unicoder_writeCStringToFile+0x7d>
mov    %eax,%r12d
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r15,%rbx,1),%esi
mov    %r13,%rdi
mov    %r14d,%edx
call   1030 <unicoder_writeCodePointToFile@plt>
add    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <unicoder_writeCStringToFile+0x60>
jmp    119f <unicoder_writeCStringToFile+0x7f>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @unicoder_writeCStringToFile(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%13 = load i32*, i32** %5
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %56
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 -1, i32* %4
br label %56
20: ; preds = %16
%21 = load i32, i32* %7
%22 = icmp ult i32 %21, 1
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %7
%25 = icmp ult i32 6, %24
br i1 %25, label %26, label %27
26: ; preds = %23, %20
store i32 -2, i32* %4
br label %56
27: ; preds = %23
%28 = load i8*, i8** %6
%29 = call i32 @strnlen(i8* %28, i32 1000005)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp ugt i32 %30, 1000000
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 -32, i32* %4
br label %56
33: ; preds = %27
store i32 0, i32* %9
store i32 0, i32* %11
br label %34
34: ; preds = %51, %33
%35 = load i32, i32* %9
%36 = load i32, i32* %8
%37 = icmp ult i32 %35, %36
br i1 %37, label %38, label %54
38: ; preds = %34
%39 = load i32*, i32** %5
%40 = load i8*, i8** %6
%41 = load i32, i32* %9
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = load i32, i32* %7
%46 = call i64 @unicoder_writeCodePointToFile(i32* %39, i8 signext %44, i32 %45)
%47 = load i32, i32* %11
%48 = zext i32 %47 to i64
%49 = add nsw i64 %48, %46
%50 = trunc i64 %49 to i32
store i32 %50, i32* %11
br label %51
51: ; preds = %38
%52 = load i32, i32* %9
%53 = add i32 %52, 1
store i32 %53, i32* %9
br label %34
54: ; preds = %34
%55 = load i32, i32* %11
store i32 %55, i32* %4
br label %56
56: ; preds = %54, %32, %26, %19, %15
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
define i32 @unicoder_writeCStringToFile(i32* %0, i8* %1, i32 %2) {
%4 = icmp eq i32* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
br i1 %6, label %27, label %7
7: ; preds = %3
%8 = add i32 %2, -7
%9 = icmp ult i32 %8, -6
br i1 %9, label %27, label %10
10: ; preds = %7
%11 = tail call i32 @strnlen(i8* %1, i32 1000005)
%12 = icmp ugt i32 %11, 1000000
br i1 %12, label %27, label %13
13: ; preds = %10
%14 = icmp eq i32 %11, 0
br i1 %14, label %27, label %15
15: ; preds = %13
%16 = zext i32 %11 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %25, %17 ]
%19 = phi i32 [ 0, %15 ], [ %24, %17 ]
%20 = getelementptr inbounds i8, i8* %1, i64 %18
%21 = load i8, i8* %20
%22 = tail call i64 @unicoder_writeCodePointToFile(i32* %0, i8 signext %21, i32 %2)
%23 = trunc i64 %22 to i32
%24 = add i32 %19, %23
%25 = add nuw nsw i64 %18, 1
%26 = icmp eq i64 %25, %16
br i1 %26, label %27, label %17
27: ; preds = %17, %13, %10, %7, %3
%28 = phi i32 [ -1, %3 ], [ -2, %7 ], [ -32, %10 ], [ 0, %13 ], [ %24, %17 ]
ret i32 %28
}