#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 */
struct stat {
  scalar_t__ st_size;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ fstat(int, struct stat *);
char *myStrStr(char *, char *);
int /*<<< orphan*/ myitoa(int, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char **, int);
int /*<<< orphan*/ write(int, char *, int);
void get_name(int uid) {
  int fd = open("/etc/passwd", O_RDONLY), i;
  char buf[100000] = {'\0'};
  char num[100000] = {0};
  myitoa(uid, num);
  struct stat sb;
  fstat(fd, &sb);
  read(fd, &buf, (int)sb.st_size);
  char *ptr = myStrStr(buf, num);
  char *temp;
  while (*(ptr) != '\n') {
    ptr--;
  }
  ptr++;
  temp = ptr;
  i = 0;
  while (*(ptr) != ':') {
    ptr++;
    i++;
  }
  write(1, temp, i);
  write(1, " ", 1);
  return;
}


x86 assembly (clang, -O0):
<get_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30d70,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe72(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
lea    -0x186b0(%rbp),%rdi
xor    %esi,%esi
mov    $0x186a0,%edx
call   1050 <memset@plt>
lea    -0x30d50(%rbp),%rdi
xor    %esi,%esi
mov    $0x186a0,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x30d50(%rbp),%rsi
call   1070 <myitoa@plt>
mov    -0x8(%rbp),%edi
lea    -0x30d58(%rbp),%rsi
call   1090 <fstat@plt>
mov    -0x8(%rbp),%edi
lea    -0x186b0(%rbp),%rsi
mov    -0x30d58(%rbp),%rax
mov    %eax,%edx
call   1060 <read@plt>
lea    -0x186b0(%rbp),%rdi
lea    -0x30d50(%rbp),%rsi
call   1030 <myStrStr@plt>
mov    %rax,-0x30d60(%rbp)
mov    -0x30d60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1236 <get_name+0xc6>
mov    -0x30d60(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30d60(%rbp)
jmp    120c <get_name+0x9c>
mov    -0x30d60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30d60(%rbp)
mov    -0x30d60(%rbp),%rax
mov    %rax,-0x30d68(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x30d60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
je     1290 <get_name+0x120>
mov    -0x30d60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30d60(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    125d <get_name+0xed>
mov    -0x30d68(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    $0x1,%edx
lea    0xd5c(%rip),%rsi
mov    %edx,%edi
call   1040 <write@plt>
add    $0x30d70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x30d58,%rsp
mov    %edi,%r15d
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
lea    0x186b0(%rsp),%r14
mov    $0x186a0,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x10(%rsp),%rbp
mov    $0x186a0,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
call   1070 <myitoa@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1090 <fstat@plt>
mov    0x8(%rsp),%edx
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <read@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <myStrStr@plt>
add    $0x2,%rax
cs nopw 0x0(%rax,%rax,1)
cmpb   $0xa,-0x2(%rax)
lea    -0x1(%rax),%rax
jne    1200 <get_name+0x90>
xor    %edx,%edx
cmpb   $0x3a,(%rax)
je     122b <get_name+0xbb>
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x3a,0x1(%rax,%rdx,1)
lea    0x1(%rdx),%rdx
jne    1220 <get_name+0xb0>
mov    $0x1,%edi
mov    %rax,%rsi
call   1040 <write@plt>
lea    0xdcd(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1040 <write@plt>
add    $0x30d58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@.str.1 = [2 x i8] c" \00"
define void @get_name(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100000 x i8]
%6 = alloca [100000 x i8]
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %2
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %3
%12 = bitcast [100000 x i8]* %5 to i8*
%13 = bitcast [100000 x i8]* %6 to i8*
%14 = load i32, i32* %2
%15 = getelementptr inbounds [100000 x i8], [100000 x i8]* %6, i64 0, i64 0
%16 = call i32 @myitoa(i32 %14, i8* %15)
%17 = load i32, i32* %3
%18 = call i32 @fstat(i32 %17, %struct.stat* %7)
%19 = load i32, i32* %3
%20 = bitcast [100000 x i8]* %5 to i8**
%21 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%22 = load i64, i64* %21
%23 = trunc i64 %22 to i32
%24 = call i32 @read(i32 %19, i8** %20, i32 %23)
%25 = getelementptr inbounds [100000 x i8], [100000 x i8]* %5, i64 0, i64 0
%26 = getelementptr inbounds [100000 x i8], [100000 x i8]* %6, i64 0, i64 0
%27 = call i8* @myStrStr(i8* %25, i8* %26)
store i8* %27, i8** %8
br label %28
28: ; preds = %33, %1
%29 = load i8*, i8** %8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %8
br label %28
36: ; preds = %28
%37 = load i8*, i8** %8
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %8
%39 = load i8*, i8** %8
store i8* %39, i8** %9
store i32 0, i32* %4
br label %40
40: ; preds = %45, %36
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 58
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %8
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %40
50: ; preds = %40
%51 = load i8*, i8** %9
%52 = load i32, i32* %4
%53 = call i32 @write(i32 1, i8* %51, i32 %52)
%54 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [12 x i8] c"/etc/passwd\00"
@O_RDONLY = global i32 0
@.str.1 = [2 x i8] c" \00"
define void @get_name(i32 %0) {
%2 = alloca [100000 x i8]
%3 = alloca [100000 x i8]
%4 = alloca %struct.stat
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds [100000 x i8], [100000 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%9 = call i32 @myitoa(i32 %0, i8* %8)
%10 = bitcast %struct.stat* %4 to i8*
%11 = call i32 @fstat(i32 %6, %struct.stat* %4)
%12 = bitcast [100000 x i8]* %2 to i8**
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
%16 = call i32 @read(i32 %6, i8** %12, i32 %15)
%17 = call i8* @myStrStr(i8* %7, i8* %8)
br label %18
18: ; preds = %18, %1
%19 = phi i8* [ %17, %1 ], [ %22, %18 ]
%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
%24 = getelementptr inbounds i8, i8* %19, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 58
br i1 %26, label %34, label %27
27: ; preds = %23, %27
%28 = phi i32 [ %31, %27 ], [ 0, %23 ]
%29 = phi i8* [ %30, %27 ], [ %24, %23 ]
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = add nuw nsw i32 %28, 1
%32 = load i8, i8* %30
%33 = icmp eq i8 %32, 58
br i1 %33, label %34, label %27
34: ; preds = %27, %23
%35 = phi i32 [ 0, %23 ], [ %31, %27 ]
%36 = call i32 @write(i32 1, i8* %24, i32 %35)
%37 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
ret void
}