#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*/ getLine(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, ...);
char *strtok(char *, char *);
int main() {
  char str[80];
  char *tokenPtr;
  int areaCode;
  long number, num2;
  printf("Enter phone number: ");
  getLine(str, 80);
  tokenPtr = strtok(str, " ()-");
  int i = 0;
  while (tokenPtr != NULL) {
    if (i == 0)
      sscanf(tokenPtr, "%d", &areaCode);
    else if (i == 1) {
      sscanf(tokenPtr, "%ld", &number);
      number *= 10000;
    } else {
      sscanf(tokenPtr, "%ld", &num2);
      number += num2;
    }
    i++;
    tokenPtr = strtok(NULL, " ()-");
  }
  printf("Area code = %d\n", areaCode);
  printf("Number = %li\n", number);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
call   1050 <getLine@plt>
lea    -0x60(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x84(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     1242 <main+0x102>
cmpl   $0x0,-0x84(%rbp)
jne    11bf <main+0x7f>
mov    -0x68(%rbp),%rdi
lea    0xe6b(%rip),%rsi
lea    -0x6c(%rbp),%rdx
mov    $0x0,%al
call   1040 <sscanf@plt>
jmp    121a <main+0xda>
cmpl   $0x1,-0x84(%rbp)
jne    11f3 <main+0xb3>
mov    -0x68(%rbp),%rdi
lea    0xe46(%rip),%rsi
lea    -0x78(%rbp),%rdx
mov    $0x0,%al
call   1040 <sscanf@plt>
imul   $0x2710,-0x78(%rbp),%rax
mov    %rax,-0x78(%rbp)
jmp    1215 <main+0xd5>
mov    -0x68(%rbp),%rdi
lea    0xe1f(%rip),%rsi
lea    -0x80(%rbp),%rdx
mov    $0x0,%al
call   1040 <sscanf@plt>
mov    -0x80(%rbp),%rax
add    -0x78(%rbp),%rax
mov    %rax,-0x78(%rbp)
jmp    121a <main+0xda>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xde1(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x68(%rbp)
jmp    118c <main+0x4c>
mov    -0x6c(%rbp),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x78(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x50,%esi
call   1050 <getLine@plt>
lea    0xea0(%rip),%rbx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <strtok@plt>
lea    0xe96(%rip),%r14
lea    0xe8c(%rip),%r12
lea    0x14(%rsp),%r13
lea    0x18(%rsp),%rbp
xor    %r15d,%r15d
jmp    11ca <main+0x8a>
nopl   (%rax)
mov    %r14,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <sscanf@plt>
mov    0x18(%rsp),%rax
add    %rax,0x8(%rsp)
add    $0x1,%r15d
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     120f <main+0xcf>
mov    %rax,%rdi
cmp    $0x1,%r15d
je     11f0 <main+0xb0>
test   %r15d,%r15d
jne    11a0 <main+0x60>
mov    %r12,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1040 <sscanf@plt>
jmp    11b7 <main+0x77>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1040 <sscanf@plt>
imul   $0x2710,0x8(%rsp),%rax
mov    %rax,0x8(%rsp)
jmp    11b7 <main+0x77>
mov    0x14(%rsp),%esi
lea    0xe07(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%rsi
lea    0xe04(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Enter phone number: \00"
@.str.1 = [5 x i8] c" ()-\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [16 x i8] c"Area code = %d\0A\00"
@.str.5 = [14 x i8] c"Number = %li\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%10 = call i32 @getLine(i8* %9, i32 80)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%12 = call i8* @strtok(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %3
store i32 0, i32* %7
br label %13
13: ; preds = %37, %0
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %41
16: ; preds = %13
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = call i32 (i8*, i8*, ...) @sscanf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
br label %37
22: ; preds = %16
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i8*, i8** %3
%27 = call i32 (i8*, i8*, ...) @sscanf(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %5)
%28 = load i64, i64* %5
%29 = mul nsw i64 %28, 10000
store i64 %29, i64* %5
br label %36
30: ; preds = %22
%31 = load i8*, i8** %3
%32 = call i32 (i8*, i8*, ...) @sscanf(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %6)
%33 = load i64, i64* %6
%34 = load i64, i64* %5
%35 = add nsw i64 %34, %33
store i64 %35, i64* %5
br label %36
36: ; preds = %30, %25
br label %37
37: ; preds = %36, %19
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %40, i8** %3
br label %13
41: ; preds = %13
%42 = load i32, i32* %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load i64, i64* %5
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"Enter phone number: \00"
@.str.1 = [5 x i8] c" ()-\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%ld\00"
@.str.4 = [16 x i8] c"Area code = %d\0A\00"
@.str.5 = [14 x i8] c"Number = %li\0A\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
%7 = bitcast i64* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @getLine(i8* %5, i32 80)
%11 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i8* %11, null
br label %13
13: ; preds = %0, %27
%14 = phi i32 [ %28, %27 ], [ 0, %0 ]
%15 = phi i8* [ %29, %27 ], [ %11, %0 ]
switch i32 %14, label %22 [
i32 0, label %16
i32 1, label %18
]
16: ; preds = %13
%17 = call i32 (i8*, i8*, ...) @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %27
18: ; preds = %13
%19 = call i32 (i8*, i8*, ...) @sscanf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %3)
%20 = load i64, i64* %3
%21 = mul nsw i64 %20, 10000
store i64 %21, i64* %3
br label %27
22: ; preds = %13
%23 = call i32 (i8*, i8*, ...) @sscanf(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64* %4)
%24 = load i64, i64* %4
%25 = load i64, i64* %3
%26 = add nsw i64 %25, %24
store i64 %26, i64* %3
br label %27
27: ; preds = %18, %22, %16
%28 = add nuw nsw i32 %14, 1
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %13
31: ; preds = %27
%32 = load i32, i32* %2
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = load i64, i64* %3
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 %34)
ret i32 0
}