#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
char *getenv(char const *);
int /*<<< orphan*/ printf(char *, char const *, int);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int askforint(const char *question, const char *envname, int deflt) {
  int res;
  char buf[80];
  char *env;
  env = getenv(envname);
  if (env && sscanf(env, "%d", &res) == 1)
    return res;
  (void)printf("%s (%d)\n", question, deflt);
  res = deflt;
  if (fgets(buf, 80, stdin))
    sscanf(buf, "%d", &res);
  return res;
}


x86 assembly (clang, -O0):
<askforint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     1196 <askforint+0x56>
mov    -0x78(%rbp),%rdi
lea    0xe87(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1196 <askforint+0x56>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ea <askforint+0xaa>
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x70(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11e4 <askforint+0xa4>
lea    -0x70(%rbp),%rdi
lea    0xe25(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<askforint>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %edx,%ebx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1172 <askforint+0x32>
lea    0xea0(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
je     11ba <askforint+0x7a>
lea    0xe8a(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <printf@plt>
mov    %ebx,0xc(%rsp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rdi
mov    $0x50,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11ba <askforint+0x7a>
lea    0xe55(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
mov    0xc(%rsp),%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%s (%d)\0A\00"
@stdin = global i32 0
define i32 @askforint(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [80 x i8]
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %6
%12 = call i8* @getenv(i8* %11)
store i8* %12, i8** %10
%13 = load i8*, i8** %10
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load i8*, i8** %10
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i32, i32* %8
store i32 %20, i32* %4
br label %35
21: ; preds = %15, %3
%22 = load i8*, i8** %5
%23 = load i32, i32* %7
%24 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %23)
%25 = load i32, i32* %7
store i32 %25, i32* %8
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%27 = load i32, i32* @stdin
%28 = call i64 @fgets(i8* %26, i32 80, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %21
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%32 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
br label %33
33: ; preds = %30, %21
%34 = load i32, i32* %8
store i32 %34, i32* %4
br label %35
35: ; preds = %33, %19
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%s (%d)\0A\00"
@stdin = global i32 0
define i32 @askforint(i8* %0, i8* nocapture %1, i32 %2) {
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%8 = tail call i8* @getenv(i8* %1)
%9 = icmp eq i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %20, label %13
13: ; preds = %10, %3
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %2)
store i32 %2, i32* %4
%15 = load i32, i32* @stdin
%16 = call i64 @fgets(i8* %7, i32 80, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
br label %20
20: ; preds = %13, %18, %10
%21 = load i32, i32* %4
ret i32 %21
}