#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*/ free(char *);
char *get_line(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, unsigned short *);
int /*<<< orphan*/ stdin;
void AskForPort(unsigned short *port) {
  char *text;
  printf("enter port number (return if 5000)\n");
  text = get_line(stdin);
  if (*text == '\0')
    *port = 5000;
  else
    sscanf(text, "%u", port);
  free(text);
}


x86 assembly (clang, -O0):
<AskForPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
call   1040 <get_line@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1188 <AskForPort+0x48>
mov    -0x8(%rbp),%rax
movw   $0x1388,(%rax)
jmp    119c <AskForPort+0x5c>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe8d(%rip),%rsi
call   1060 <sscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AskForPort>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
call   1050 <get_line@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     117d <AskForPort+0x3d>
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <sscanf@plt>
jmp    1183 <AskForPort+0x43>
movw   $0x1388,(%r14)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"enter port number (return if 5000)\0A\00"
@stdin = global i32 0
@.str.1 = [3 x i8] c"%u\00"
define void @AskForPort(i16* %0) {
%2 = alloca i16*
%3 = alloca i8*
store i16* %0, i16** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i8* @get_line(i32 %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i16*, i16** %2
store i16 5000, i16* %12
br label %17
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = load i16*, i16** %2
%16 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i16* %15)
br label %17
17: ; preds = %13, %11
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [3 x i8] c"%u\00"
@str = [35 x i8] c"enter port number (return if 5000)\00"
define void @AskForPort(i16* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%3 = load i32, i32* @stdin
%4 = tail call i8* @get_line(i32 %3)
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i16 5000, i16* %0
br label %10
8: ; preds = %1
%9 = tail call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i16* %0)
br label %10
10: ; preds = %8, %7
%11 = tail call i32 @free(i8* %4)
ret void
}