#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 */
scalar_t__ big5_wctomb_zint(unsigned int *, unsigned int const);
int big5_wctomb(unsigned char *r, const unsigned int wc) {
  unsigned int c;
  if (wc < 0x80) {
    *r = (unsigned char)wc;
    return 1;
  }
  if (big5_wctomb_zint(&c, wc)) {
    r[0] = (unsigned char)(c >> 8);
    r[1] = (unsigned char)(c & 0xff);
    return 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<big5_wctomb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jae    1143 <big5_wctomb+0x33>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    118b <big5_wctomb+0x7b>
mov    -0x14(%rbp),%esi
lea    -0x18(%rbp),%rdi
call   1030 <big5_wctomb_zint@plt>
cmp    $0x0,%rax
je     1184 <big5_wctomb+0x74>
mov    -0x18(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x2,-0x4(%rbp)
jmp    118b <big5_wctomb+0x7b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<big5_wctomb>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
cmp    $0x7f,%esi
ja     1127 <big5_wctomb+0x17>
mov    %sil,(%rbx)
mov    $0x1,%eax
jmp    114b <big5_wctomb+0x3b>
lea    0xc(%rsp),%rdi
call   1030 <big5_wctomb_zint@plt>
test   %rax,%rax
je     1149 <big5_wctomb+0x39>
movzwl 0xc(%rsp),%eax
rol    $0x8,%ax
mov    %ax,(%rbx)
mov    $0x2,%eax
jmp    114b <big5_wctomb+0x3b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @big5_wctomb(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp ult i32 %7, 128
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* %5
%11 = trunc i32 %10 to i8
%12 = load i8*, i8** %4
store i8 %11, i8* %12
store i32 1, i32* %3
br label %29
13: ; preds = %2
%14 = load i32, i32* %5
%15 = call i64 @big5_wctomb_zint(i32* %6, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i32, i32* %6
%19 = lshr i32 %18, 8
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 %20, i8* %22
%23 = load i32, i32* %6
%24 = and i32 %23, 255
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8 %25, i8* %27
store i32 2, i32* %3
br label %29
28: ; preds = %13
store i32 0, i32* %3
br label %29
29: ; preds = %28, %17, %9
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @big5_wctomb(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp ult i32 %1, 128
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = trunc i32 %1 to i8
store i8 %7, i8* %0
br label %17
8: ; preds = %2
%9 = call i64 @big5_wctomb_zint(i32* %3, i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %8
%12 = load i32, i32* %3
%13 = lshr i32 %12, 8
%14 = trunc i32 %13 to i8
store i8 %14, i8* %0
%15 = trunc i32 %12 to i8
%16 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %15, i8* %16
br label %17
17: ; preds = %8, %11, %6
%18 = phi i32 [ 1, %6 ], [ 2, %11 ], [ 0, %8 ]
ret i32 %18
}