#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(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *getcmdline(char *prompt) {
  static char buf[1024];
  printf("%s", prompt);
  fflush(stdout);
  if (!fgets(buf, sizeof buf, stdin)) {
    fprintf(stderr, "fgets failed\n");
    exit(1);
  }
  return buf;
}


x86 assembly (clang, -O0):
<getcmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
lea    0x2ed6(%rip),%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    11bc <getcmdline+0x6c>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0x2e9d(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcmdline>:
push   %rax
mov    %rdi,%rsi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
lea    0x2ee2(%rip),%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
test   %eax,%eax
je     1195 <getcmdline+0x45>
lea    0x2ecd(%rip),%rax
pop    %rcx
ret
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@getcmdline.buf = internal global [1024 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
@stdout = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"fgets failed\0A\00"
define i8* @getcmdline(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = load i32, i32* @stdout
%6 = call i32 @fflush(i32 %5)
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getcmdline.buf, i64 0, i64 0), i32 1024, i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getcmdline.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@getcmdline.buf = internal global [1024 x i8] zeroinitializer
@.str = [3 x i8] c"%s\00"
@stdout = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"fgets failed\0A\00"
define i8* @getcmdline(i8* %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = load i32, i32* @stdout
%4 = tail call i32 @fflush(i32 %3)
%5 = load i32, i32* @stdin
%6 = tail call i32 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getcmdline.buf, i64 0, i64 0), i32 1024, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @getcmdline.buf, i64 0, i64 0)
}