#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int getchar();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
int strlen(char *);
char *Wgetpass(char *msg) {
  char buf[1024] = {0};
  char a[2] = {0};
  int c;
  printf("%s", msg);
  a[1] = 0;
  while ((c = getchar()) != '\n') {
    a[0] = c;
    if (strlen(buf) > sizeof(buf) - 1)
      break;
    strcat(buf, a);
  }
  return strdup(buf);
}


x86 assembly (clang, -O0):
<Wgetpass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x412(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rsi
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
movb   $0x0,-0x411(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x418(%rbp)
cmp    $0xa,%eax
je     1205 <Wgetpass+0xa5>
mov    -0x418(%rbp),%eax
mov    %al,-0x412(%rbp)
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
cltq
cmp    $0x3ff,%rax
jbe    11ed <Wgetpass+0x8d>
jmp    1205 <Wgetpass+0xa5>
lea    -0x410(%rbp),%rdi
lea    -0x412(%rbp),%rsi
call   1070 <strcat@plt>
jmp    11ac <Wgetpass+0x4c>
lea    -0x410(%rbp),%rdi
call   1080 <strdup@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Wgetpass>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe7b(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
movb   $0x0,0xf(%rsp)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%eax
je     11da <Wgetpass+0x7a>
lea    0x10(%rsp),%rbx
lea    0xe(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %al,0xe(%rsp)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x3ff,%eax
ja     11da <Wgetpass+0x7a>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%eax
jne    11b0 <Wgetpass+0x50>
lea    0x10(%rsp),%rdi
call   1080 <strdup@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i8* @Wgetpass(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca [2 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = bitcast [1024 x i8]* %3 to i8*
%7 = bitcast [2 x i8]* %4 to i8*
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %10
br label %11
11: ; preds = %23, %1
%12 = call i32 (...) @getchar()
store i32 %12, i32* %5
%13 = icmp ne i32 %12, 10
br i1 %13, label %14, label %27
14: ; preds = %11
%15 = load i32, i32* %5
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
store i8 %16, i8* %17
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = icmp ugt i64 %20, 1023
br i1 %21, label %22, label %23
22: ; preds = %14
br label %27
23: ; preds = %14
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%25 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%26 = call i32 @strcat(i8* %24, i8* %25)
br label %11
27: ; preds = %22, %11
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%29 = call i8* @strdup(i8* %28)
ret i8* %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define noalias i8* @Wgetpass(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca i16
%4 = bitcast i16* %3 to [2 x i8]*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = bitcast i16* %3 to i8*
%7 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
store i8 0, i8* %8
%9 = call i32 (...) @getchar()
%10 = icmp eq i32 %9, 10
br i1 %10, label %20, label %11
11: ; preds = %1, %16
%12 = phi i32 [ %18, %16 ], [ %9, %1 ]
%13 = trunc i32 %12 to i8
store i8 %13, i8* %6
%14 = call i32 @strlen(i8* %5)
%15 = icmp ugt i32 %14, 1023
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = call i32 @strcat(i8* %5, i8* %6)
%18 = call i32 (...) @getchar()
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %11
20: ; preds = %16, %11, %1
%21 = call i8* @strdup(i8* %5)
ret i8* %21
}