#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*/ execve(char *, int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int main() {
  open("/dev/tty/0", 0);
  open("/dev/tty/0", 0);
  open("/dev/tty/0", 0);
  char *welcome_msg = "=======================[ Welcome to the yet un-named OS "
                      "]=======================";
  {
    char __buf__[7];
    sprintf(__buf__, "\033[%dm", 36);
    fprintf(stderr, __buf__);
  };
  fprintf(stderr, "\n\n%s\n", welcome_msg);
  {
    char __buf__[7];
    sprintf(__buf__, "\033[%dm", 0);
    fprintf(stderr, __buf__);
  };
  fprintf(stderr, "Currently any user name shall work ;)\n");
  char usr[80];
  while (!usr[0] || usr[0] == '\n') {
    fprintf(stderr, "username : ");
    read(0, usr, 80);
  }
  int i;
  for (i = 0; usr[i] != '\n'; ++i)
    ;
  usr[i] = 0;
  char _usr[80];
  strcat(_usr, "USER=");
  strcat(_usr, usr);
  char *env[] = {_usr, "PWD=/", NULL};
  execve("/bin/shell", NULL, env);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
lea    0xe79(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
lea    0xe6b(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
lea    0xe68(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x17(%rbp),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x24,%edx
call   1080 <sprintf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    -0x17(%rbp),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x1e(%rbp),%rdi
lea    0xe66(%rip),%rsi
xor    %edx,%edx
call   1080 <sprintf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    -0x1e(%rbp),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%al
cmpb   $0x0,-0x70(%rbp)
mov    %al,-0xf1(%rbp)
je     124a <main+0xea>
movsbl -0x70(%rbp),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0xf1(%rbp)
mov    -0xf1(%rbp),%al
test   $0x1,%al
jne    125d <main+0xfd>
jmp    1289 <main+0x129>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x70(%rbp),%rsi
xor    %edi,%edi
mov    $0x50,%edx
call   1030 <read@plt>
jmp    1228 <main+0xc8>
movl   $0x0,-0x74(%rbp)
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
je     12b5 <main+0x155>
jmp    12a7 <main+0x147>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1290 <main+0x130>
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0xd0(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1070 <strcat@plt>
lea    -0xd0(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0xd0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    0xdab(%rip),%rax
mov    %rax,-0xe8(%rbp)
movq   $0x0,-0xe0(%rbp)
lea    -0xf0(%rbp),%rdx
lea    0xd91(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <execve@plt>
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc8,%rsp
lea    0xe8b(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <open@plt>
lea    0xec2(%rip),%r15
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x24,%edx
call   1080 <sprintf@plt>
mov    0x2e2a(%rip),%r12
mov    (%r12),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r12),%edi
lea    0xe93(%rip),%rsi
lea    0xe35(%rip),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %edx,%edx
call   1080 <sprintf@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r12),%edi
lea    0xe60(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe79(%rip),%rbx
jmp    1242 <main+0xe2>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x50,%edx
call   1030 <read@plt>
movzbl 0x20(%rsp),%eax
test   %al,%al
je     1220 <main+0xc0>
cmp    $0xa,%al
je     1220 <main+0xc0>
xor    %eax,%eax
nopl   0x0(%rax)
cmpb   $0xa,0x21(%rsp,%rax,1)
lea    0x1(%rax),%rax
jne    1250 <main+0xf0>
mov    %eax,%eax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xe32(%rip),%rsi
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,(%rsp)
lea    0xe13(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe04(%rip),%rdi
mov    %rsp,%rdx
xor    %esi,%esi
call   1040 <execve@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/tty/0\00"
@.str.1 = [81 x i8] c"=======================[ Welcome to the yet un-named OS ]=======================\00"
@.str.2 = [6 x i8] c"\1B[%dm\00"
@stderr = global i32 0
@.str.3 = [6 x i8] c"\0A\0A%s\0A\00"
@.str.4 = [39 x i8] c"Currently any user name shall work ;)\0A\00"
@.str.5 = [12 x i8] c"username : \00"
@.str.6 = [6 x i8] c"USER=\00"
@.str.7 = [6 x i8] c"PWD=/\00"
@.str.8 = [11 x i8] c"/bin/shell\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [7 x i8]
%4 = alloca [7 x i8]
%5 = alloca [80 x i8]
%6 = alloca i32
%7 = alloca [80 x i8]
%8 = alloca [3 x i8*]
store i32 0, i32* %1
%9 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
%10 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
%11 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
store i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0), i8** %2
%12 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%13 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 36)
%14 = load i32, i32* @stderr
%15 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* %15)
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %2
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%21 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 0)
%22 = load i32, i32* @stderr
%23 = getelementptr inbounds [7 x i8], [7 x i8]* %4, i64 0, i64 0
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* %23)
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %38, %0
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 10
br label %36
36: ; preds = %31, %27
%37 = phi i1 [ true, %27 ], [ %35, %31 ]
br i1 %37, label %38, label %43
38: ; preds = %36
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%42 = call i32 @read(i32 0, i8* %41, i32 80)
br label %27
43: ; preds = %36
store i32 0, i32* %6
br label %44
44: ; preds = %52, %43
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 10
br i1 %50, label %51, label %55
51: ; preds = %44
br label %52
52: ; preds = %51
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %44
55: ; preds = %44
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %57
store i8 0, i8* %58
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%60 = call i32 @strcat(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%61 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%62 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%63 = call i32 @strcat(i8* %61, i8* %62)
%64 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%65 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
store i8* %65, i8** %64
%66 = getelementptr inbounds i8*, i8** %64, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %66
%67 = getelementptr inbounds i8*, i8** %66, i64 1
store i8* null, i8** %67
%68 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%69 = call i32 @execve(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32* null, i8** %68)
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/tty/0\00"
@.str.1 = [81 x i8] c"=======================[ Welcome to the yet un-named OS ]=======================\00"
@.str.2 = [6 x i8] c"\1B[%dm\00"
@stderr = global i32 0
@.str.3 = [6 x i8] c"\0A\0A%s\0A\00"
@.str.4 = [39 x i8] c"Currently any user name shall work ;)\0A\00"
@.str.5 = [12 x i8] c"username : \00"
@.str.6 = [6 x i8] c"USER=\00"
@.str.7 = [6 x i8] c"PWD=/\00"
@.str.8 = [11 x i8] c"/bin/shell\00"
define i32 @main() {
%1 = alloca [7 x i8]
%2 = alloca [7 x i8]
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca [3 x i8*]
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
%7 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
%9 = getelementptr inbounds [7 x i8], [7 x i8]* %1, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 36)
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* %9)
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [7 x i8], [7 x i8]* %2, i64 0, i64 0
%16 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 0)
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* %15)
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
br label %22
22: ; preds = %24, %0
%23 = phi i8 [ %28, %24 ], [ undef, %0 ]
switch i8 %23, label %29 [
i8 10, label %24
i8 0, label %24
]
24: ; preds = %22, %22
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%27 = call i32 @read(i32 0, i8* %21, i32 80)
%28 = load i8, i8* %21
br label %22
29: ; preds = %22, %29
%30 = phi i64 [ %34, %29 ], [ 1, %22 ]
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 10
%34 = add nuw i64 %30, 1
br i1 %33, label %35, label %29
35: ; preds = %29
%36 = and i64 %30, 4294967295
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %36
store i8 0, i8* %37
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @strcat(i8* %38, i8* %21)
%41 = bitcast [3 x i8*]* %5 to i8*
%42 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
store i8* %38, i8** %42
%43 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %43
%44 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 2
store i8* null, i8** %44
%45 = call i32 @execve(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32* null, i8** %42)
ret i32 0
}