#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 uint8_t;

/* Variables and functions */
int split_plmn(uint8_t plmn[3], uint8_t mcc[3], uint8_t mnc[3]) {
  if (plmn == NULL) {
    return -1;
  }
  mcc[0] = plmn[0] & 0x0F;
  mcc[1] = (plmn[0] & 0xF0) >> 4;
  mcc[2] = plmn[1] & 0x0F;
  if ((plmn[1] & 0xF0) == 0xF0) {
    mnc[1] = plmn[2] & 0x0F;
    mnc[2] = (plmn[2] & 0xF0) >> 4;
    mnc[0] = 0;
  } else {
    mnc[0] = plmn[2] & 0x0F;
    mnc[1] = (plmn[2] & 0xF0) >> 4;
    mnc[2] = ((plmn[1] & 0xF0) >> 4);
  }
  return 0;
}


x86 assembly (clang, -O0):
<split_plmn>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1127 <split_plmn+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <split_plmn+0xf0>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    $0xf,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
and    $0xf,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
and    $0xf0,%eax
cmp    $0xf0,%eax
jne    11ab <split_plmn+0xab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
and    $0xf,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
jmp    11e9 <split_plmn+0xe9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
and    $0xf,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_plmn>:
test   %rdi,%rdi
je     1148 <split_plmn+0x48>
mov    (%rdi),%eax
and    $0xf,%eax
mov    %eax,(%rsi)
mov    (%rdi),%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %eax,0x4(%rsi)
mov    0x4(%rdi),%eax
and    $0xf,%eax
mov    %eax,0x8(%rsi)
mov    0x4(%rdi),%ecx
mov    0x8(%rdi),%eax
not    %ecx
and    $0xf,%eax
test   $0xf0,%cl
jne    114e <split_plmn+0x4e>
mov    %eax,0x4(%rdx)
mov    0x8(%rdi),%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %eax,0x8(%rdx)
movl   $0x0,(%rdx)
xor    %eax,%eax
ret
mov    $0xffffffff,%eax
ret
mov    %eax,(%rdx)
mov    0x8(%rdi),%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %eax,0x4(%rdx)
mov    0x4(%rdi),%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %eax,0x8(%rdx)
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @split_plmn(i32* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 -1, i32* %4
br label %74
11: ; preds = %3
%12 = load i32*, i32** %5
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = and i32 %14, 15
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i64 0
store i32 %15, i32* %17
%18 = load i32*, i32** %5
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = and i32 %20, 240
%22 = ashr i32 %21, 4
%23 = load i32*, i32** %6
%24 = getelementptr inbounds i32, i32* %23, i64 1
store i32 %22, i32* %24
%25 = load i32*, i32** %5
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
%28 = and i32 %27, 15
%29 = load i32*, i32** %6
%30 = getelementptr inbounds i32, i32* %29, i64 2
store i32 %28, i32* %30
%31 = load i32*, i32** %5
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = load i32, i32* %32
%34 = and i32 %33, 240
%35 = icmp eq i32 %34, 240
br i1 %35, label %36, label %52
36: ; preds = %11
%37 = load i32*, i32** %5
%38 = getelementptr inbounds i32, i32* %37, i64 2
%39 = load i32, i32* %38
%40 = and i32 %39, 15
%41 = load i32*, i32** %7
%42 = getelementptr inbounds i32, i32* %41, i64 1
store i32 %40, i32* %42
%43 = load i32*, i32** %5
%44 = getelementptr inbounds i32, i32* %43, i64 2
%45 = load i32, i32* %44
%46 = and i32 %45, 240
%47 = ashr i32 %46, 4
%48 = load i32*, i32** %7
%49 = getelementptr inbounds i32, i32* %48, i64 2
store i32 %47, i32* %49
%50 = load i32*, i32** %7
%51 = getelementptr inbounds i32, i32* %50, i64 0
store i32 0, i32* %51
br label %73
52: ; preds = %11
%53 = load i32*, i32** %5
%54 = getelementptr inbounds i32, i32* %53, i64 2
%55 = load i32, i32* %54
%56 = and i32 %55, 15
%57 = load i32*, i32** %7
%58 = getelementptr inbounds i32, i32* %57, i64 0
store i32 %56, i32* %58
%59 = load i32*, i32** %5
%60 = getelementptr inbounds i32, i32* %59, i64 2
%61 = load i32, i32* %60
%62 = and i32 %61, 240
%63 = ashr i32 %62, 4
%64 = load i32*, i32** %7
%65 = getelementptr inbounds i32, i32* %64, i64 1
store i32 %63, i32* %65
%66 = load i32*, i32** %5
%67 = getelementptr inbounds i32, i32* %66, i64 1
%68 = load i32, i32* %67
%69 = and i32 %68, 240
%70 = ashr i32 %69, 4
%71 = load i32*, i32** %7
%72 = getelementptr inbounds i32, i32* %71, i64 2
store i32 %70, i32* %72
br label %73
73: ; preds = %52, %36
store i32 0, i32* %4
br label %74
74: ; preds = %73, %10
%75 = load i32, i32* %4
ret i32 %75
}

LLVM IR (-O2):
define i32 @split_plmn(i32* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %37, label %5
5: ; preds = %3
%6 = load i32, i32* %0
%7 = and i32 %6, 15
store i32 %7, i32* %1
%8 = load i32, i32* %0
%9 = lshr i32 %8, 4
%10 = and i32 %9, 15
%11 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %10, i32* %11
%12 = getelementptr inbounds i32, i32* %0, i64 1
%13 = load i32, i32* %12
%14 = and i32 %13, 15
%15 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %14, i32* %15
%16 = load i32, i32* %12
%17 = and i32 %16, 240
%18 = icmp eq i32 %17, 240
%19 = getelementptr inbounds i32, i32* %0, i64 2
%20 = load i32, i32* %19
%21 = and i32 %20, 15
br i1 %18, label %22, label %28
22: ; preds = %5
%23 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %21, i32* %23
%24 = load i32, i32* %19
%25 = lshr i32 %24, 4
%26 = and i32 %25, 15
%27 = getelementptr inbounds i32, i32* %2, i64 2
store i32 %26, i32* %27
store i32 0, i32* %2
br label %37
28: ; preds = %5
store i32 %21, i32* %2
%29 = load i32, i32* %19
%30 = lshr i32 %29, 4
%31 = and i32 %30, 15
%32 = getelementptr inbounds i32, i32* %2, i64 1
store i32 %31, i32* %32
%33 = load i32, i32* %12
%34 = lshr i32 %33, 4
%35 = and i32 %34, 15
%36 = getelementptr inbounds i32, i32* %2, i64 2
store i32 %35, i32* %36
br label %37
37: ; preds = %22, %28, %3
%38 = phi i32 [ -1, %3 ], [ 0, %28 ], [ 0, %22 ]
ret i32 %38
}