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

/* Variables and functions */
int possibly_trunc(int32_t i) {
  int32_t end;
  int32_t has_2 = 0;
  end = i % 10;
  if (end != 7 && end != 3)
    return 0;
  for (; i; i /= 10) {
    end = (i % 10);
    if (end % 2 == 0) {
      if (end == 2) {
        if (has_2++)
          return 0;
      } else {
        return 0;
      }
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<possibly_trunc>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x7,-0xc(%rbp)
je     113c <possibly_trunc+0x3c>
cmpl   $0x3,-0xc(%rbp)
je     113c <possibly_trunc+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    11cc <possibly_trunc+0xcc>
jmp    1141 <possibly_trunc+0x41>
cmpl   $0x0,-0x8(%rbp)
je     11c5 <possibly_trunc+0xc5>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ad <possibly_trunc+0xad>
cmpl   $0x2,-0xc(%rbp)
jne    119c <possibly_trunc+0x9c>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
je     1197 <possibly_trunc+0x97>
movl   $0x0,-0x4(%rbp)
jmp    11cc <possibly_trunc+0xcc>
jmp    11a8 <possibly_trunc+0xa8>
movl   $0x0,-0x4(%rbp)
jmp    11cc <possibly_trunc+0xcc>
jmp    11ad <possibly_trunc+0xad>
jmp    11b2 <possibly_trunc+0xb2>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1141 <possibly_trunc+0x41>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<possibly_trunc>:
movslq %edi,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ecx
and    $0xfffffffb,%ecx
xor    %eax,%eax
cmp    $0x3,%ecx
jne    116f <possibly_trunc+0x6f>
test   %edi,%edi
je     1170 <possibly_trunc+0x70>
xor    %ecx,%ecx
jmp    113a <possibly_trunc+0x3a>
add    $0x9,%edi
cmp    $0x12,%edi
mov    %edx,%edi
jbe    1170 <possibly_trunc+0x70>
movslq %edi,%rsi
imul   $0x66666667,%rsi,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x22,%rdx
add    %eax,%edx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
test   $0x1,%sil
jne    1130 <possibly_trunc+0x30>
xor    %eax,%eax
cmp    $0x2,%esi
jne    116f <possibly_trunc+0x6f>
test   %ecx,%ecx
mov    $0x1,%ecx
je     1130 <possibly_trunc+0x30>
ret
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i32 @possibly_trunc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = srem i32 %6, 10
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 7
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 0, i32* %2
br label %40
14: ; preds = %10, %1
br label %15
15: ; preds = %36, %14
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %39
18: ; preds = %15
%19 = load i32, i32* %3
%20 = srem i32 %19, 10
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = srem i32 %21, 2
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %18
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
%30 = icmp ne i32 %28, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 0, i32* %2
br label %40
32: ; preds = %27
br label %34
33: ; preds = %24
store i32 0, i32* %2
br label %40
34: ; preds = %32
br label %35
35: ; preds = %34, %18
br label %36
36: ; preds = %35
%37 = load i32, i32* %3
%38 = sdiv i32 %37, 10
store i32 %38, i32* %3
br label %15
39: ; preds = %15
store i32 1, i32* %2
br label %40
40: ; preds = %39, %33, %31, %13
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @possibly_trunc(i32 %0) {
%2 = srem i32 %0, 10
%3 = and i32 %2, -5
%4 = icmp eq i32 %3, 3
br i1 %4, label %5, label %22
5: ; preds = %1
%6 = icmp eq i32 %0, 0
br i1 %6, label %22, label %7
7: ; preds = %5, %18
%8 = phi i32 [ %19, %18 ], [ 0, %5 ]
%9 = phi i32 [ %11, %18 ], [ %0, %5 ]
%10 = srem i32 %9, 10
%11 = sdiv i32 %9, 10
%12 = and i32 %10, 1
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %7
%15 = icmp eq i32 %10, 2
%16 = icmp eq i32 %8, 0
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %22
18: ; preds = %14, %7
%19 = phi i32 [ %8, %7 ], [ 1, %14 ]
%20 = add i32 %9, 9
%21 = icmp ult i32 %20, 19
br i1 %21, label %22, label %7
22: ; preds = %14, %18, %5, %1
%23 = phi i32 [ 0, %1 ], [ 1, %5 ], [ 0, %14 ], [ 1, %18 ]
ret i32 %23
}