#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memcmp(char *, char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int strtol(char *, int /*<<< orphan*/ *, int);
int getPIN() {
  char pin[4];
  scanf("%4c", pin);
  if (!memcmp(pin, "0000", 4))
    return 0;
  int r = strtol(pin, NULL, 10);
  if (!r)
    exit(EXIT_FAILURE);
  return r;
}


x86 assembly (clang, -O0):
<getPIN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rsi
lea    0xead(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    1182 <getPIN+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <getPIN+0x75>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11af <getPIN+0x6f>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPIN>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
lea    0xc(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     1194 <getPIN+0x54>
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
test   %eax,%eax
jne    1196 <getPIN+0x56>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%4c\00"
@.str.1 = [5 x i8] c"0000\00"
@EXIT_FAILURE = global i32 0
define i32 @getPIN() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%7 = call i32 @memcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %0
store i32 0, i32* %1
br label %20
10: ; preds = %0
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%12 = call i32 @strtol(i8* %11, i32* null, i32 10)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
%19 = load i32, i32* %3
store i32 %19, i32* %1
br label %20
20: ; preds = %18, %9
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [4 x i8] c"%4c\00"
@.str.1 = [5 x i8] c"0000\00"
@EXIT_FAILURE = global i32 0
define i32 @getPIN() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i32 @memcmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%5 = icmp eq i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = call i32 @strtol(i8* nocapture %2, i32* null, i32 10)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %6, %0
%13 = phi i32 [ 0, %0 ], [ %7, %6 ]
ret i32 %13
}