#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 PATH_MAX;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int getUserInput(char *input) {
  char buf[255];
  char *s = buf;
  char cwd[PATH_MAX + 1];
  getcwd(cwd, PATH_MAX + 1);
  printf("[3150 Shell:%s]=> ", cwd);
  if (fgets(buf, 255, stdin) == NULL) {
    putchar('\n');
    return 1;
  }
  for (; *s != '\n'; s++)
    ;
  *s = '\0';
  strcpy(input, buf);
  return 0;
}


x86 assembly (clang, -O0):
<getUserInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x120(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x138(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x128(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
add    $0x1,%esi
call   1060 <getcwd@plt>
mov    -0x138(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    120d <getUserInput+0xbd>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x12c(%rbp)
jmp    126c <getUserInput+0x11c>
jmp    1212 <getUserInput+0xc2>
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1241 <getUserInput+0xf1>
jmp    122a <getUserInput+0xda>
mov    -0x118(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
jmp    1212 <getUserInput+0xc2>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x12c(%rbp)
mov    -0x120(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getUserInput>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
mov    %rsp,%r15
mov    0x2e83(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rsp,%rbx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    (%rax),%esi
add    $0x1,%esi
mov    %rbx,%rdi
call   1060 <getcwd@plt>
lea    0xe69(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
lea    -0x120(%rbp),%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     11f0 <getUserInput+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0xa,(%rbx)
lea    0x1(%rbx),%rbx
jne    11d0 <getUserInput+0x80>
movb   $0x0,-0x1(%rbx)
lea    -0x120(%rbp),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
xor    %eax,%eax
jmp    11ff <getUserInput+0xaf>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%eax
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [19 x i8] c"[3150 Shell:%s]=> \00"
@stdin = global i32 0
define i32 @getUserInput(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [255 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
store i8* %9, i8** %5
%10 = load i32, i32* @PATH_MAX
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %6
%14 = alloca i8, i64 %12
store i64 %12, i64* %7
%15 = load i32, i32* @PATH_MAX
%16 = add nsw i32 %15, 1
%17 = call i32 @getcwd(i8* %14, i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %14)
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%20 = load i32, i32* @stdin
%21 = call i32* @fgets(i8* %19, i32 255, i32 %20)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %1
%24 = call i32 @putchar(i8 signext 10)
store i32 1, i32* %2
store i32 1, i32* %8
br label %40
25: ; preds = %1
br label %26
26: ; preds = %32, %25
%27 = load i8*, i8** %5
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 10
br i1 %30, label %31, label %35
31: ; preds = %26
br label %32
32: ; preds = %31
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %5
br label %26
35: ; preds = %26
%36 = load i8*, i8** %5
store i8 0, i8* %36
%37 = load i8*, i8** %3
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%39 = call i32 @strcpy(i8* %37, i8* %38)
store i32 0, i32* %2
store i32 1, i32* %8
br label %40
40: ; preds = %35, %23
%41 = load i8*, i8** %6
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [19 x i8] c"[3150 Shell:%s]=> \00"
@stdin = global i32 0
define i32 @getUserInput(i8* %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @PATH_MAX
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @PATH_MAX
%10 = add nsw i32 %9, 1
%11 = call i32 @getcwd(i8* %8, i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%13 = load i32, i32* @stdin
%14 = call i32* @fgets(i8* %3, i32 255, i32 %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @putchar(i8 signext 10)
br label %25
18: ; preds = %1, %18
%19 = phi i8* [ %22, %18 ], [ %3, %1 ]
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 10
%22 = getelementptr inbounds i8, i8* %19, i64 1
br i1 %21, label %23, label %18
23: ; preds = %18
store i8 0, i8* %19
%24 = call i32 @strcpy(i8* %0, i8* %3)
br label %25
25: ; preds = %23, %16
%26 = phi i32 [ 1, %16 ], [ 0, %23 ]
ret i32 %26
}