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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strsep(char **, char *);
int getpublicandprivatekey(char *key, char *ret) {
  char buf[1024];
  char *res;
  FILE *fd;
  char *mkey;
  char *mval;
  fd = fopen("/etc/publickey", "r");
  if (fd == NULL)
    return (0);
  for (;;) {
    res = fgets(buf, sizeof(buf), fd);
    if (res == NULL) {
      fclose(fd);
      return (0);
    }
    if (res[0] == '#')
      continue;
    else if (res[0] == '+') {
      continue;
    } else {
      mkey = strsep(&res, "\t ");
      if (mkey == NULL) {
        fprintf(stderr, "Bad record in %s -- %s", "/etc/publickey", buf);
        continue;
      }
      do {
        mval = strsep(&res, " \t#\n");
      } while (mval != NULL && !*mval);
      if (mval == NULL) {
        fprintf(stderr, "Bad record in %s val problem - %s", "/etc/publickey",
                buf);
        continue;
      }
      if (strcmp(mkey, key) == 0) {
        strcpy(ret, mval);
        fclose(fd);
        return (1);
      }
    }
  }
}


x86 assembly (clang, -O0):
<getpublicandprivatekey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe76(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jne    11b7 <getpublicandprivatekey+0x47>
movl   $0x0,-0x4(%rbp)
jmp    1360 <getpublicandprivatekey+0x1f0>
jmp    11bc <getpublicandprivatekey+0x4c>
lea    -0x420(%rbp),%rdi
mov    -0x430(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    1201 <getpublicandprivatekey+0x91>
mov    -0x430(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1360 <getpublicandprivatekey+0x1f0>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1219 <getpublicandprivatekey+0xa9>
jmp    11bc <getpublicandprivatekey+0x4c>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1231 <getpublicandprivatekey+0xc1>
jmp    11bc <getpublicandprivatekey+0x4c>
lea    -0x428(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   1080 <strsep@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    1281 <getpublicandprivatekey+0x111>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rcx
lea    0xda4(%rip),%rsi
lea    0xd89(%rip),%rdx
call   1070 <fprintf@plt>
jmp    11bc <getpublicandprivatekey+0x4c>
jmp    1286 <getpublicandprivatekey+0x116>
lea    -0x428(%rbp),%rdi
lea    0xd97(%rip),%rsi
call   1080 <strsep@plt>
mov    %rax,-0x440(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x440(%rbp)
mov    %al,-0x441(%rbp)
je     12cb <getpublicandprivatekey+0x15b>
mov    -0x440(%rbp),%rax
cmpb   $0x0,(%rax)
setne  %al
xor    $0xff,%al
mov    %al,-0x441(%rbp)
mov    -0x441(%rbp),%al
test   $0x1,%al
jne    1286 <getpublicandprivatekey+0x116>
cmpq   $0x0,-0x440(%rbp)
jne    130f <getpublicandprivatekey+0x19f>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rcx
lea    0xd32(%rip),%rsi
lea    0xcfb(%rip),%rdx
call   1070 <fprintf@plt>
jmp    11bc <getpublicandprivatekey+0x4c>
mov    -0x438(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1351 <getpublicandprivatekey+0x1e1>
mov    -0x18(%rbp),%rdi
mov    -0x440(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x430(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1360 <getpublicandprivatekey+0x1f0>
jmp    1356 <getpublicandprivatekey+0x1e6>
jmp    135b <getpublicandprivatekey+0x1eb>
jmp    11bc <getpublicandprivatekey+0x4c>
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpublicandprivatekey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rsi,%r14
mov    %rdi,0x18(%rsp)
lea    0xe70(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     128e <getpublicandprivatekey+0x11e>
mov    %rax,%rbx
lea    0x20(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rax,0x8(%rsp)
xor    %ebp,%ebp
test   %rax,%rax
je     1294 <getpublicandprivatekey+0x124>
mov    %r14,0x10(%rsp)
lea    0x20(%rsp),%rbp
lea    0x8(%rsp),%r14
lea    0xe4b(%rip),%r12
jmp    121b <getpublicandprivatekey+0xab>
lea    0xe47(%rip),%rsi
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rdx
mov    %rbp,%rcx
call   1070 <fprintf@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1292 <getpublicandprivatekey+0x122>
mov    (%rax),%al
or     $0x8,%al
cmp    $0x2b,%al
je     1201 <getpublicandprivatekey+0x91>
mov    %r14,%rdi
lea    0xde4(%rip),%rsi
call   1080 <strsep@plt>
mov    %rax,%r15
lea    0xdd8(%rip),%rsi
test   %rax,%rax
je     11e9 <getpublicandprivatekey+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <strsep@plt>
test   %rax,%rax
je     11e2 <getpublicandprivatekey+0x72>
mov    %rax,%r13
cmpb   $0x0,(%rax)
je     1250 <getpublicandprivatekey+0xe0>
mov    %r15,%rdi
mov    0x18(%rsp),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1201 <getpublicandprivatekey+0x91>
mov    0x10(%rsp),%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%ebp
jmp    1294 <getpublicandprivatekey+0x124>
xor    %ebp,%ebp
jmp    129c <getpublicandprivatekey+0x12c>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/etc/publickey\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"\09 \00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"Bad record in %s -- %s\00"
@.str.4 = [5 x i8] c" \09#\0A\00"
@.str.5 = [34 x i8] c"Bad record in %s val problem - %s\00"
define i32 @getpublicandprivatekey(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %81
15: ; preds = %2
br label %16
16: ; preds = %80, %63, %43, %38, %31, %15
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %8
%19 = call i8* @fgets(i8* %17, i32 1024, i32* %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32*, i32** %8
%24 = call i32 @fclose(i32* %23)
store i32 0, i32* %3
br label %81
25: ; preds = %16
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 35
br i1 %30, label %31, label %32
31: ; preds = %25
br label %16
32: ; preds = %25
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 43
br i1 %37, label %38, label %39
38: ; preds = %32
br label %16
39: ; preds = %32
%40 = call i8* @strsep(i8** %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %45)
br label %16
47: ; preds = %39
br label %48
48: ; preds = %58, %47
%49 = call i8* @strsep(i8** %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i8* %49, i8** %10
br label %50
50: ; preds = %48
%51 = load i8*, i8** %10
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %58
53: ; preds = %50
%54 = load i8*, i8** %10
%55 = load i8, i8* %54
%56 = icmp ne i8 %55, 0
%57 = xor i1 %56, true
br label %58
58: ; preds = %53, %50
%59 = phi i1 [ false, %50 ], [ %57, %53 ]
br i1 %59, label %48, label %60
60: ; preds = %58
%61 = load i8*, i8** %10
%62 = icmp eq i8* %61, null
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = load i32, i32* @stderr
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%66 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %65)
br label %16
67: ; preds = %60
%68 = load i8*, i8** %9
%69 = load i8*, i8** %4
%70 = call i64 @strcmp(i8* %68, i8* %69)
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %67
%73 = load i8*, i8** %5
%74 = load i8*, i8** %10
%75 = call i32 @strcpy(i8* %73, i8* %74)
%76 = load i32*, i32** %8
%77 = call i32 @fclose(i32* %76)
store i32 1, i32* %3
br label %81
78: ; preds = %67
br label %79
79: ; preds = %78
br label %80
80: ; preds = %79
br label %16
81: ; preds = %72, %22, %14
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [15 x i8] c"/etc/publickey\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"\09 \00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"Bad record in %s -- %s\00"
@.str.4 = [5 x i8] c" \09#\0A\00"
@.str.5 = [34 x i8] c"Bad record in %s val problem - %s\00"
define i32 @getpublicandprivatekey(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast i8** %4 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %39, label %9
9: ; preds = %2
%10 = call i8* @fgets(i8* %5, i32 1024, i32* %7)
store i8* %10, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %36, label %12
12: ; preds = %9, %22
%13 = phi i8* [ %23, %22 ], [ %10, %9 ]
%14 = load i8, i8* %13
switch i8 %14, label %15 [
i8 35, label %22
i8 43, label %22
]
15: ; preds = %12
%16 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %25
18: ; preds = %25, %15
%19 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %15 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), %25 ]
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %22
22: ; preds = %18, %31, %12, %12
%23 = call i8* @fgets(i8* %5, i32 1024, i32* %7)
store i8* %23, i8** %4
%24 = icmp eq i8* %23, null
br i1 %24, label %36, label %12
25: ; preds = %15, %28
%26 = call i8* @strsep(i8** %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %18, label %28
28: ; preds = %25
%29 = load i8, i8* %26
%30 = icmp eq i8 %29, 0
br i1 %30, label %25, label %31
31: ; preds = %28
%32 = call i64 @strcmp(i8* %16, i8* %0)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %22
34: ; preds = %31
%35 = call i32 @strcpy(i8* %1, i8* %26)
br label %36
36: ; preds = %22, %9, %34
%37 = phi i32 [ 1, %34 ], [ 0, %9 ], [ 0, %22 ]
%38 = call i32 @fclose(i32* %7)
br label %39
39: ; preds = %36, %2
%40 = phi i32 [ 0, %2 ], [ %37, %36 ]
ret i32 %40
}