#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 key_netstarg {
  scalar_t__ *st_priv_key;
  int /*<<< orphan*/ st_netname;
  scalar_t__ *st_pub_key;
};

/* Variables and functions */
int /*<<< orphan*/ MAXNETNAMELEN;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ getnetname(char *);
int /*<<< orphan*/ getpass(char *);
int /*<<< orphan*/ getsecretkey(char *, char *, int /*<<< orphan*/);
scalar_t__ key_setnet(struct key_netstarg *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strdup(char *);
int main(void) {
  char fullname[MAXNETNAMELEN + 1];
  struct key_netstarg netst;
  if (!getnetname(fullname)) {
    fprintf(stderr, "netname lookup failed -- make sure the ");
    fprintf(stderr, "system domain name is set.\n");
    exit(1);
  }
  if (!getsecretkey(fullname, (char *)&(netst.st_priv_key),
                    getpass("Password:"))) {
    fprintf(stderr, "Can't find %s's secret key\n", fullname);
    exit(1);
  }
  if (netst.st_priv_key[0] == 0) {
    fprintf(stderr, "Password incorrect for %s\n", fullname);
    exit(1);
  }
  netst.st_pub_key[0] = 0;
  netst.st_netname = strdup(fullname);
  if (key_setnet(&netst) < 0) {
    fprintf(stderr, "Could not set %s's secret key\n", fullname);
    fprintf(stderr, "Maybe the keyserver is down?\n");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
call   1060 <getnetname@plt>
cmp    $0x0,%eax
jne    11f4 <main+0x84>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xe41(%rip),%rdi
call   1070 <getpass@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1040 <getsecretkey@plt>
cmp    $0x0,%eax
jne    1245 <main+0xd5>
mov    -0x38(%rbp),%rdx
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x30(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1278 <main+0x108>
mov    -0x38(%rbp),%rdx
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
call   1090 <strdup@plt>
mov    %eax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <key_setnet@plt>
cmp    $0x0,%rax
jge    12de <main+0x16e>
mov    -0x38(%rbp),%rdx
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1060 <getnetname@plt>
test   %eax,%eax
jne    11d5 <main+0x65>
mov    0x2e35(%rip),%rbx
mov    (%rbx),%edi
lea    0xe4c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe64(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe68(%rip),%rdi
call   1070 <getpass@plt>
lea    -0x28(%rbp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <getsecretkey@plt>
test   %eax,%eax
jne    1205 <main+0x95>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
jmp    121f <main+0xaf>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1233 <main+0xc3>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    %rbx,%rdi
call   1090 <strdup@plt>
mov    %eax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <key_setnet@plt>
test   %rax,%rax
jns    1281 <main+0x111>
mov    0x2d82(%rip),%r14
mov    (%r14),%edi
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edi
lea    0xe28(%rip),%rsi
jmp    11c4 <main+0x54>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.key_netstarg = type { i64*, i32, i64* }
@MAXNETNAMELEN = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"netname lookup failed -- make sure the \00"
@.str.1 = [28 x i8] c"system domain name is set.\0A\00"
@.str.2 = [10 x i8] c"Password:\00"
@.str.3 = [28 x i8] c"Can't find %s's secret key\0A\00"
@.str.4 = [27 x i8] c"Password incorrect for %s\0A\00"
@.str.5 = [31 x i8] c"Could not set %s's secret key\0A\00"
@.str.6 = [30 x i8] c"Maybe the keyserver is down?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca %struct.key_netstarg
store i32 0, i32* %1
%5 = load i32, i32* @MAXNETNAMELEN
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %2
%9 = alloca i8, i64 %7
store i64 %7, i64* %3
%10 = call i32 @getnetname(i8* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = getelementptr inbounds %struct.key_netstarg, %struct.key_netstarg* %4, i32 0, i32 0
%20 = bitcast i64** %19 to i8*
%21 = call i32 @getpass(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @getsecretkey(i8* %9, i8* %20, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = getelementptr inbounds %struct.key_netstarg, %struct.key_netstarg* %4, i32 0, i32 0
%30 = load i64*, i64** %29
%31 = getelementptr inbounds i64, i64* %30, i64 0
%32 = load i64, i64* %31
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %28
%39 = getelementptr inbounds %struct.key_netstarg, %struct.key_netstarg* %4, i32 0, i32 2
%40 = load i64*, i64** %39
%41 = getelementptr inbounds i64, i64* %40, i64 0
store i64 0, i64* %41
%42 = call i32 @strdup(i8* %9)
%43 = getelementptr inbounds %struct.key_netstarg, %struct.key_netstarg* %4, i32 0, i32 1
store i32 %42, i32* %43
%44 = call i64 @key_setnet(%struct.key_netstarg* %4)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %38
%53 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.key_netstarg = type { i64*, i32, i64* }
@MAXNETNAMELEN = global i32 0
@stderr = global i32 0
@.str = [40 x i8] c"netname lookup failed -- make sure the \00"
@.str.1 = [28 x i8] c"system domain name is set.\0A\00"
@.str.2 = [10 x i8] c"Password:\00"
@.str.3 = [28 x i8] c"Can't find %s's secret key\0A\00"
@.str.4 = [27 x i8] c"Password incorrect for %s\0A\00"
@.str.5 = [31 x i8] c"Could not set %s's secret key\0A\00"
@.str.6 = [30 x i8] c"Maybe the keyserver is down?\0A\00"
define i32 @main() {
%1 = alloca %struct.key_netstarg
%2 = load i32, i32* @MAXNETNAMELEN
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast %struct.key_netstarg* %1 to i8*
%7 = call i32 @getnetname(i8* %5)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32 @getpass(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @getsecretkey(i8* %5, i8* %6, i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = getelementptr inbounds %struct.key_netstarg, %struct.key_netstarg* %1, i64 0, i32 0
%25 = load i64*, i64** %24
%26 = load i64, i64* %25
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23
%33 = getelementptr inbounds %struct.key_netstarg, %struct.key_netstarg* %1, i64 0, i32 2
%34 = load i64*, i64** %33
store i64 0, i64* %34
%35 = call i32 @strdup(i8* %5)
%36 = getelementptr inbounds %struct.key_netstarg, %struct.key_netstarg* %1, i64 0, i32 1
store i32 %35, i32* %36
%37 = call i64 @key_setnet(%struct.key_netstarg* %1)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %32
%46 = call i32 @exit(i32 0)
unreachable
}