#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*/ authexit(int);
int /*<<< orphan*/ execv(char const *, char **);
void *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char const *);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ sscanf(char const *, char *, int *);
int /*<<< orphan*/ write(int, char *, int);
void authmod_fail_completely() {
  char **argv;
  int argc, n;
  const char *p = getenv("AUTHARGC");
  char buf[20];
  if (!p || sscanf(p, "%d", &argc) <= 0 || argc <= 0) {
    write(2, "AUTHFAILURE\n", 12);
    authexit(1);
  }
  if ((argv = (char **)malloc((argc + 1) * sizeof(char *))) == 0) {
    perror("malloc");
    authexit(1);
  }
  for (n = 0; n < argc; n++) {
    sprintf(buf, "AUTHARGV%d", n);
    if ((argv[n] = getenv(buf)) == 0)
      authexit(1);
  }
  argv[n] = 0;
  p = getenv("AUTHUSER");
  if (!p)
    authexit(1);
  execv(p, argv);
  perror(p);
  authexit(1);
}


x86 assembly (clang, -O0):
<authmod_fail_completely>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe71(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cb <authmod_fail_completely+0x4b>
mov    -0x18(%rbp),%rdi
lea    0xe77(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
jle    11cb <authmod_fail_completely+0x4b>
cmpl   $0x0,-0xc(%rbp)
jg     11eb <authmod_fail_completely+0x6b>
mov    $0x2,%edi
lea    0xe32(%rip),%rsi
mov    $0xc,%edx
call   1040 <write@plt>
mov    $0x1,%edi
call   1050 <authexit@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1222 <authmod_fail_completely+0xa2>
lea    0xe03(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1050 <authexit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1284 <authmod_fail_completely+0x104>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xdda(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <getenv@plt>
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    1271 <authmod_fail_completely+0xf1>
mov    $0x1,%edi
call   1050 <authexit@plt>
jmp    1276 <authmod_fail_completely+0xf6>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1229 <authmod_fail_completely+0xa9>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
lea    0xd8d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12b9 <authmod_fail_completely+0x139>
mov    $0x1,%edi
call   1050 <authexit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <execv@plt>
mov    -0x18(%rbp),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1050 <authexit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<authmod_fail_completely>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe6e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    11c2 <authmod_fail_completely+0x42>
lea    0xe66(%rip),%rsi
mov    $0x2,%edi
mov    $0xc,%edx
call   1040 <write@plt>
mov    $0x1,%edi
call   1050 <authexit@plt>
mov    0xc(%rsp),%eax
jmp    11e3 <authmod_fail_completely+0x63>
lea    0xe5c(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1070 <sscanf@plt>
test   %rax,%rax
jle    119c <authmod_fail_completely+0x1c>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    119c <authmod_fail_completely+0x1c>
lea    0x8(,%rax,8),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    120d <authmod_fail_completely+0x8d>
lea    0xe18(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1050 <authexit@plt>
cmpl   $0x0,0xc(%rsp)
jle    1268 <authmod_fail_completely+0xe8>
xor    %ebx,%ebx
lea    0xe00(%rip),%r15
lea    0x10(%rsp),%r12
jmp    123e <authmod_fail_completely+0xbe>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jge    126a <authmod_fail_completely+0xea>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1090 <sprintf@plt>
mov    %r12,%rdi
call   1030 <getenv@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
jne    1230 <authmod_fail_completely+0xb0>
mov    $0x1,%edi
call   1050 <authexit@plt>
jmp    1230 <authmod_fail_completely+0xb0>
xor    %ebx,%ebx
movq   $0x0,(%r14,%rbx,8)
lea    0xdaf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1290 <authmod_fail_completely+0x110>
mov    $0x1,%edi
call   1050 <authexit@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <execv@plt>
mov    %rbx,%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1050 <authexit@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"AUTHARGC\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"AUTHFAILURE\0A\00"
@.str.3 = [7 x i8] c"malloc\00"
@.str.4 = [11 x i8] c"AUTHARGV%d\00"
@.str.5 = [9 x i8] c"AUTHUSER\00"
define void @authmod_fail_completely() {
%1 = alloca i8**
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [20 x i8]
%6 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %16
9: ; preds = %0
%10 = load i8*, i8** %4
%11 = call i64 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%12 = icmp sle i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i32, i32* %2
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13, %9, %0
%17 = call i32 @write(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 12)
%18 = call i32 @authexit(i32 1)
br label %19
19: ; preds = %16, %13
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 8
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8**
store i8** %26, i8*** %1
%27 = icmp eq i8** %26, null
br i1 %27, label %28, label %31
28: ; preds = %19
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @authexit(i32 1)
br label %31
31: ; preds = %28, %19
store i32 0, i32* %3
br label %32
32: ; preds = %50, %31
%33 = load i32, i32* %3
%34 = load i32, i32* %2
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %53
36: ; preds = %32
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%38 = load i32, i32* %3
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%41 = call i8* @getenv(i8* %40)
%42 = load i8**, i8*** %1
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
store i8* %41, i8** %45
%46 = icmp eq i8* %41, null
br i1 %46, label %47, label %49
47: ; preds = %36
%48 = call i32 @authexit(i32 1)
br label %49
49: ; preds = %47, %36
br label %50
50: ; preds = %49
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %32
53: ; preds = %32
%54 = load i8**, i8*** %1
%55 = load i32, i32* %3
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %54, i64 %56
store i8* null, i8** %57
%58 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
store i8* %58, i8** %4
%59 = load i8*, i8** %4
%60 = icmp ne i8* %59, null
br i1 %60, label %63, label %61
61: ; preds = %53
%62 = call i32 @authexit(i32 1)
br label %63
63: ; preds = %61, %53
%64 = load i8*, i8** %4
%65 = load i8**, i8*** %1
%66 = call i32 @execv(i8* %64, i8** %65)
%67 = load i8*, i8** %4
%68 = call i32 @perror(i8* %67)
%69 = call i32 @authexit(i32 1)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"AUTHARGC\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"AUTHFAILURE\0A\00"
@.str.3 = [7 x i8] c"malloc\00"
@.str.4 = [11 x i8] c"AUTHARGV%d\00"
@.str.5 = [9 x i8] c"AUTHUSER\00"
define void @authmod_fail_completely() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = bitcast i32* %1 to i8*
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%6 = icmp eq i8* %4, null
br i1 %6, label %13, label %7
7: ; preds = %0
%8 = call i64 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = icmp slt i64 %8, 1
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
%12 = select i1 %9, i1 true, i1 %11
br i1 %12, label %13, label %17
13: ; preds = %7, %0
%14 = call i32 @write(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 12)
%15 = call i32 @authexit(i32 1)
%16 = load i32, i32* %1
br label %17
17: ; preds = %7, %13
%18 = phi i32 [ %10, %7 ], [ %16, %13 ]
%19 = shl i32 %18, 3
%20 = add i32 %19, 8
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8**
%23 = icmp eq i64 %21, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @authexit(i32 1)
br label %27
27: ; preds = %24, %17
%28 = load i32, i32* %1
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %46
30: ; preds = %27, %39
%31 = phi i64 [ %40, %39 ], [ 0, %27 ]
%32 = trunc i64 %31 to i32
%33 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%34 = call i8* @getenv(i8* %5)
%35 = getelementptr inbounds i8*, i8** %22, i64 %31
store i8* %34, i8** %35
%36 = icmp eq i8* %34, null
br i1 %36, label %37, label %39
37: ; preds = %30
%38 = call i32 @authexit(i32 1)
br label %39
39: ; preds = %30, %37
%40 = add nuw nsw i64 %31, 1
%41 = load i32, i32* %1
%42 = sext i32 %41 to i64
%43 = icmp slt i64 %40, %42
br i1 %43, label %30, label %44
44: ; preds = %39
%45 = and i64 %40, 4294967295
br label %46
46: ; preds = %44, %27
%47 = phi i64 [ 0, %27 ], [ %45, %44 ]
%48 = getelementptr inbounds i8*, i8** %22, i64 %47
store i8* null, i8** %48
%49 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 @authexit(i32 1)
br label %53
53: ; preds = %51, %46
%54 = call i32 @execv(i8* %49, i8** %22)
%55 = call i32 @perror(i8* %49)
%56 = call i32 @authexit(i32 1)
ret void
}