#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 ean_make_checksum(unsigned char *, int /*<<< orphan*/);
unsigned char *strchr(unsigned char *, char);
int /*<<< orphan*/ strcpy(unsigned char *, int /*<<< orphan*/);
int strlen(unsigned char *);
int /*<<< orphan*/ upc_e_to_a0(unsigned char *);
char *upc_e_to_a(unsigned char *text) {
  static unsigned char result[16], *spc;
  int len, chk;
  spc = strchr(text, ' ');
  if (spc)
    len = spc - text;
  else
    len = strlen(text);
  switch (len) {
  case 6:
    strcpy(result, upc_e_to_a0(text));
    return result;
  case 7:
    if (text[0] == '0' || text[0] == '1') {
      strcpy(result, upc_e_to_a0(text + 1));
      result[0] = text[0];
      return result;
    }
    strcpy(result, upc_e_to_a0(text));
    chk = ean_make_checksum(result, 0);
    if (chk == (text[len - 1] - '0'))
      return result;
    return NULL;
  case 8:
    if (text[0] == '0' || text[0] == '1') {
      strcpy(result, upc_e_to_a0(text + 1));
      result[0] = text[0];
      chk = ean_make_checksum(result, 0);
      if (chk == (text[len - 1] - '0'))
        return result;
    }
  default:
    return NULL;
  }
}


x86 assembly (clang, -O0):
<upc_e_to_a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,0x2eff(%rip)
cmpq   $0x0,0x2ef7(%rip)
je     1195 <upc_e_to_a+0x45>
mov    0x2eea(%rip),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    11a1 <upc_e_to_a+0x51>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x6,%eax
je     11d7 <upc_e_to_a+0x87>
jmp    11b5 <upc_e_to_a+0x65>
mov    -0x1c(%rbp),%eax
sub    $0x7,%eax
je     11fe <upc_e_to_a+0xae>
jmp    11c6 <upc_e_to_a+0x76>
mov    -0x1c(%rbp),%eax
sub    $0x8,%eax
je     12b9 <upc_e_to_a+0x169>
jmp    134a <upc_e_to_a+0x1fa>
mov    -0x10(%rbp),%rdi
call   1070 <upc_e_to_a0@plt>
mov    %eax,%esi
lea    0x2e77(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2e6b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1352 <upc_e_to_a+0x202>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x30,%eax
je     121e <upc_e_to_a+0xce>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x31,%eax
jne    1255 <upc_e_to_a+0x105>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1070 <upc_e_to_a0@plt>
mov    %eax,%esi
lea    0x2e2c(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,0x2e1b(%rip)
lea    0x2e14(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1352 <upc_e_to_a+0x202>
mov    -0x10(%rbp),%rdi
call   1070 <upc_e_to_a0@plt>
mov    %eax,%esi
lea    0x2df9(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ded(%rip),%rdi
xor    %esi,%esi
call   1040 <ean_make_checksum@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
sub    $0x30,%ecx
cmp    %ecx,%eax
jne    12ac <upc_e_to_a+0x15c>
lea    0x2dbd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1352 <upc_e_to_a+0x202>
movq   $0x0,-0x8(%rbp)
jmp    1352 <upc_e_to_a+0x202>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x30,%eax
je     12d9 <upc_e_to_a+0x189>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x31,%eax
jne    1345 <upc_e_to_a+0x1f5>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1070 <upc_e_to_a0@plt>
mov    %eax,%esi
lea    0x2d71(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,0x2d60(%rip)
lea    0x2d59(%rip),%rdi
xor    %esi,%esi
call   1040 <ean_make_checksum@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
sub    $0x30,%ecx
cmp    %ecx,%eax
jne    1340 <upc_e_to_a+0x1f0>
lea    0x2d29(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1352 <upc_e_to_a+0x202>
jmp    1345 <upc_e_to_a+0x1f5>
jmp    134a <upc_e_to_a+0x1fa>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upc_e_to_a>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,0x2f07(%rip)
test   %rax,%rax
je     119e <upc_e_to_a+0x4e>
sub    %r14d,%eax
cmp    $0x8,%eax
je     11ab <upc_e_to_a+0x5b>
cmp    $0x7,%eax
je     11f1 <upc_e_to_a+0xa1>
cmp    $0x6,%eax
jne    11ed <upc_e_to_a+0x9d>
mov    %r14,%rdi
call   1070 <upc_e_to_a0@plt>
lea    0x2ed1(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
jmp    1252 <upc_e_to_a+0x102>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    $0x8,%eax
jne    1176 <upc_e_to_a+0x26>
mov    (%r14),%al
and    $0xfe,%al
cmp    $0x30,%al
jne    11ed <upc_e_to_a+0x9d>
lea    0x1(%r14),%rdi
call   1070 <upc_e_to_a0@plt>
lea    0x2e9c(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    (%r14),%al
mov    %al,0x2e89(%rip)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <ean_make_checksum@plt>
movzbl 0x7(%r14),%ecx
add    $0xffffffd0,%ecx
cmp    %ecx,%eax
je     1252 <upc_e_to_a+0x102>
xor    %ebx,%ebx
jmp    1252 <upc_e_to_a+0x102>
mov    (%r14),%al
and    $0xfe,%al
cmp    $0x30,%al
jne    121f <upc_e_to_a+0xcf>
lea    0x1(%r14),%rdi
call   1070 <upc_e_to_a0@plt>
lea    0x2e56(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    (%r14),%al
mov    %al,0x2e43(%rip)
jmp    1252 <upc_e_to_a+0x102>
mov    %r14,%rdi
call   1070 <upc_e_to_a0@plt>
lea    0x2e32(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <ean_make_checksum@plt>
movzbl 0x6(%r14),%ecx
add    $0xffffffd0,%ecx
cmp    %ecx,%eax
cmove  %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@upc_e_to_a.result = internal global [16 x i8] zeroinitializer
@upc_e_to_a.spc = internal global i8* null
define i8* @upc_e_to_a(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i8* @strchr(i8* %6, i8 signext 32)
store i8* %7, i8** @upc_e_to_a.spc
%8 = load i8*, i8** @upc_e_to_a.spc
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = load i8*, i8** @upc_e_to_a.spc
%12 = load i8*, i8** %3
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint i8* %12 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %4
br label %20
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
store i32 %19, i32* %4
br label %20
20: ; preds = %17, %10
%21 = load i32, i32* %4
switch i32 %21, label %97 [
i32 6, label %22
i32 7, label %26
i32 8, label %63
]
22: ; preds = %20
%23 = load i8*, i8** %3
%24 = call i32 @upc_e_to_a0(i8* %23)
%25 = call i32 @strcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 %24)
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i8** %2
br label %98
26: ; preds = %20
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %30, 48
br i1 %31, label %38, label %32
32: ; preds = %26
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = icmp eq i32 %36, 49
br i1 %37, label %38, label %46
38: ; preds = %32, %26
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = call i32 @upc_e_to_a0(i8* %40)
%42 = call i32 @strcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 %41)
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
store i8 %45, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0)
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i8** %2
br label %98
46: ; preds = %32
%47 = load i8*, i8** %3
%48 = call i32 @upc_e_to_a0(i8* %47)
%49 = call i32 @strcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 %48)
%50 = call i32 @ean_make_checksum(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 0)
store i32 %50, i32* %5
%51 = load i32, i32* %5
%52 = load i8*, i8** %3
%53 = load i32, i32* %4
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = sub nsw i32 %58, 48
%60 = icmp eq i32 %51, %59
br i1 %60, label %61, label %62
61: ; preds = %46
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i8** %2
br label %98
62: ; preds = %46
store i8* null, i8** %2
br label %98
63: ; preds = %20
%64 = load i8*, i8** %3
%65 = getelementptr inbounds i8, i8* %64, i64 0
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = icmp eq i32 %67, 48
br i1 %68, label %75, label %69
69: ; preds = %63
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i64 0
%72 = load i8, i8* %71
%73 = zext i8 %72 to i32
%74 = icmp eq i32 %73, 49
br i1 %74, label %75, label %96
75: ; preds = %69, %63
%76 = load i8*, i8** %3
%77 = getelementptr inbounds i8, i8* %76, i64 1
%78 = call i32 @upc_e_to_a0(i8* %77)
%79 = call i32 @strcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 %78)
%80 = load i8*, i8** %3
%81 = getelementptr inbounds i8, i8* %80, i64 0
%82 = load i8, i8* %81
store i8 %82, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0)
%83 = call i32 @ean_make_checksum(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 0)
store i32 %83, i32* %5
%84 = load i32, i32* %5
%85 = load i8*, i8** %3
%86 = load i32, i32* %4
%87 = sub nsw i32 %86, 1
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %85, i64 %88
%90 = load i8, i8* %89
%91 = zext i8 %90 to i32
%92 = sub nsw i32 %91, 48
%93 = icmp eq i32 %84, %92
br i1 %93, label %94, label %95
94: ; preds = %75
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i8** %2
br label %98
95: ; preds = %75
br label %96
96: ; preds = %95, %69
br label %97
97: ; preds = %20, %96
store i8* null, i8** %2
br label %98
98: ; preds = %97, %94, %62, %61, %38, %22
%99 = load i8*, i8** %2
ret i8* %99
}

LLVM IR (-O2):
@upc_e_to_a.result = internal global [16 x i8] zeroinitializer
@upc_e_to_a.spc = internal unnamed_addr global i8* null
define i8* @upc_e_to_a(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 32)
store i8* %2, i8** @upc_e_to_a.spc
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = ptrtoint i8* %2 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
br label %11
9: ; preds = %1
%10 = tail call i32 @strlen(i8* %0)
br label %11
11: ; preds = %9, %4
%12 = phi i32 [ %8, %4 ], [ %10, %9 ]
switch i32 %12, label %50 [
i32 6, label %13
i32 7, label %16
i32 8, label %35
]
13: ; preds = %11
%14 = tail call i32 @upc_e_to_a0(i8* %0)
%15 = tail call i32 @strcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 %14)
br label %51
16: ; preds = %11
%17 = load i8, i8* %0
%18 = and i8 %17, -2
%19 = icmp eq i8 %18, 48
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %0, i64 1
%22 = tail call i32 @upc_e_to_a0(i8* %21)
%23 = tail call i32 @strcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 %22)
%24 = load i8, i8* %0
store i8 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0)
br label %51
25: ; preds = %16
%26 = tail call i32 @upc_e_to_a0(i8* %0)
%27 = tail call i32 @strcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 %26)
%28 = tail call i32 @ean_make_checksum(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 0)
%29 = getelementptr inbounds i8, i8* %0, i64 6
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = add nsw i32 %31, -48
%33 = icmp eq i32 %28, %32
%34 = select i1 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i8* null
br label %51
35: ; preds = %11
%36 = load i8, i8* %0
%37 = and i8 %36, -2
%38 = icmp eq i8 %37, 48
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = getelementptr inbounds i8, i8* %0, i64 1
%41 = tail call i32 @upc_e_to_a0(i8* %40)
%42 = tail call i32 @strcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 %41)
%43 = load i8, i8* %0
store i8 %43, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0)
%44 = tail call i32 @ean_make_checksum(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), i32 0)
%45 = getelementptr inbounds i8, i8* %0, i64 7
%46 = load i8, i8* %45
%47 = zext i8 %46 to i32
%48 = add nsw i32 %47, -48
%49 = icmp eq i32 %44, %48
br i1 %49, label %51, label %50
50: ; preds = %35, %39, %11
br label %51
51: ; preds = %39, %25, %50, %20, %13
%52 = phi i8* [ null, %50 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), %20 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), %13 ], [ %34, %25 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @upc_e_to_a.result, i64 0, i64 0), %39 ]
ret i8* %52
}