#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int strtol(char *, char **, int);
int main() {
  char input[16];
  char *p;
  int a;
  printf("Type an integer: ");
  fgets(input, 16, stdin);
  a = strtol(input, &p, 10);
  if (p == input)
    puts("Invalid input");
  else
    printf("Double %d is %d\n", a, a + a);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1050 <fgets@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
lea    -0x20(%rbp),%rcx
cmp    %rcx,%rax
jne    11ab <main+0x6b>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
jmp    11c2 <main+0x82>
mov    -0x2c(%rbp),%esi
mov    -0x2c(%rbp),%edx
add    -0x2c(%rbp),%edx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1050 <fgets@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1060 <strtol@plt>
cmp    %rbx,0x8(%rsp)
je     119d <main+0x5d>
mov    %eax,%edx
add    %eax,%edx
lea    0xe8e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a9 <main+0x69>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Type an integer: \00"
@stdin = global i32 0
@.str.1 = [14 x i8] c"Invalid input\00"
@.str.2 = [17 x i8] c"Double %d is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 16, i32 %7)
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%10 = call i32 @strtol(i8* %9, i8** %3, i32 10)
store i32 %10, i32* %4
%11 = load i8*, i8** %3
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %22
16: ; preds = %0
%17 = load i32, i32* %4
%18 = load i32, i32* %4
%19 = load i32, i32* %4
%20 = add nsw i32 %18, %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %20)
br label %22
22: ; preds = %16, %14
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Type an integer: \00"
@stdin = global i32 0
@.str.1 = [14 x i8] c"Invalid input\00"
@.str.2 = [17 x i8] c"Double %d is %d\0A\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = bitcast i8** %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %3, i32 16, i32 %6)
%8 = call i32 @strtol(i8* %3, i8** %2, i32 10)
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, %3
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %16
13: ; preds = %0
%14 = shl nsw i32 %8, 1
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %14)
br label %16
16: ; preds = %13, %11
ret i32 0
}