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


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

x86 assembly (clang, -O2):
<euc_kr_wctomb>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
cmp    $0x7f,%esi
ja     1127 <euc_kr_wctomb+0x17>
mov    %sil,(%rbx)
mov    $0x1,%eax
jmp    1152 <euc_kr_wctomb+0x42>
lea    0xc(%rsp),%rdi
call   1030 <ksx1001_wctomb_zint@plt>
test   %rax,%rax
je     1150 <euc_kr_wctomb+0x40>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
shr    $0x8,%ecx
xor    $0x80,%cl
mov    %cl,(%rbx)
xor    $0x80,%al
mov    %al,0x1(%rbx)
mov    $0x2,%eax
jmp    1152 <euc_kr_wctomb+0x42>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @euc_kr_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 %31
13: ; preds = %2
%14 = load i32, i32* %5
%15 = call i64 @ksx1001_wctomb_zint(i32* %6, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = load i32, i32* %6
%19 = lshr i32 %18, 8
%20 = add i32 %19, 128
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i64 0
store i8 %21, i8* %23
%24 = load i32, i32* %6
%25 = and i32 %24, 255
%26 = add i32 %25, 128
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 %27, i8* %29
store i32 2, i32* %3
br label %31
30: ; preds = %13
store i32 0, i32* %3
br label %31
31: ; preds = %30, %17, %9
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
define i32 @euc_kr_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 %19
8: ; preds = %2
%9 = call i64 @ksx1001_wctomb_zint(i32* %3, i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %8
%12 = load i32, i32* %3
%13 = lshr i32 %12, 8
%14 = trunc i32 %13 to i8
%15 = xor i8 %14, -128
store i8 %15, i8* %0
%16 = trunc i32 %12 to i8
%17 = xor i8 %16, -128
%18 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %17, i8* %18
br label %19
19: ; preds = %8, %11, %6
%20 = phi i32 [ 1, %6 ], [ 2, %11 ], [ 0, %8 ]
ret i32 %20
}