#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 passwd {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ atol(char *);
struct passwd *getpwnam(char *);
struct passwd *getpwuid(int /*<<< orphan*/);
scalar_t__ isdigit(char);
int /*<<< orphan*/ print_passwd(struct passwd *);
passwd_keys(int number, char *key[]) {
  int result = 0;
  int i;
  for (i = 0; i < number; ++i) {
    struct passwd *pwd;
    if (isdigit(key[i][0]))
      pwd = getpwuid(atol(key[i]));
    else
      pwd = getpwnam(key[i]);
    if (pwd == NULL)
      result = 2;
    else
      print_passwd(pwd);
  }
  return result;
}


x86 assembly (clang, -O0):
<passwd_keys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1200 <passwd_keys+0xb0>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11b8 <passwd_keys+0x68>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <atol@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
jmp    11cd <passwd_keys+0x7d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <getpwnam@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e4 <passwd_keys+0x94>
movl   $0x2,-0x14(%rbp)
jmp    11ed <passwd_keys+0x9d>
mov    -0x20(%rbp),%rdi
call   1070 <print_passwd@plt>
jmp    11f2 <passwd_keys+0xa2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <passwd_keys+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passwd_keys>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    11c2 <passwd_keys+0x72>
mov    %rsi,%rbx
mov    %edi,%r15d
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    1181 <passwd_keys+0x31>
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1070 <print_passwd@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
je     11c5 <passwd_keys+0x75>
mov    (%rbx,%rbp,8),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
mov    (%rbx,%rbp,8),%rdi
test   %rax,%rax
je     11b0 <passwd_keys+0x60>
call   1060 <atol@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
jne    1170 <passwd_keys+0x20>
jmp    11ba <passwd_keys+0x6a>
nopl   0x0(%rax)
call   1050 <getpwnam@plt>
test   %rax,%rax
jne    1170 <passwd_keys+0x20>
mov    $0x2,%r14d
jmp    1178 <passwd_keys+0x28>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
define i32 @passwd_keys(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.passwd*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %45, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %48
12: ; preds = %8
%13 = load i8**, i8*** %4
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = call i64 @isdigit(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %12
%23 = load i8**, i8*** %4
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @atol(i8* %27)
%29 = call %struct.passwd* @getpwuid(i32 %28)
store %struct.passwd* %29, %struct.passwd** %7
br label %37
30: ; preds = %12
%31 = load i8**, i8*** %4
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call %struct.passwd* @getpwnam(i8* %35)
store %struct.passwd* %36, %struct.passwd** %7
br label %37
37: ; preds = %30, %22
%38 = load %struct.passwd*, %struct.passwd** %7
%39 = icmp eq %struct.passwd* %38, null
br i1 %39, label %40, label %41
40: ; preds = %37
store i32 2, i32* %5
br label %44
41: ; preds = %37
%42 = load %struct.passwd*, %struct.passwd** %7
%43 = call i32 @print_passwd(%struct.passwd* %42)
br label %44
44: ; preds = %41, %40
br label %45
45: ; preds = %44
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %8
48: ; preds = %8
%49 = load i32, i32* %5
ret i32 %49
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
define i32 @passwd_keys(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %29
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %25
%7 = phi i64 [ 0, %4 ], [ %27, %25 ]
%8 = phi i32 [ 0, %4 ], [ %26, %25 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %7
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = tail call i64 @isdigit(i8 signext %11)
%13 = icmp eq i64 %12, 0
%14 = load i8*, i8** %9
br i1 %13, label %18, label %15
15: ; preds = %6
%16 = tail call i32 @atol(i8* %14)
%17 = tail call %struct.passwd* @getpwuid(i32 %16)
br label %20
18: ; preds = %6
%19 = tail call %struct.passwd* @getpwnam(i8* %14)
br label %20
20: ; preds = %18, %15
%21 = phi %struct.passwd* [ %17, %15 ], [ %19, %18 ]
%22 = icmp eq %struct.passwd* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i32 @print_passwd(%struct.passwd* %21)
br label %25
25: ; preds = %20, %23
%26 = phi i32 [ %8, %23 ], [ 2, %20 ]
%27 = add nuw nsw i64 %7, 1
%28 = icmp eq i64 %27, %5
br i1 %28, label %29, label %6
29: ; preds = %25, %2
%30 = phi i32 [ 0, %2 ], [ %26, %25 ]
ret i32 %30
}