#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 {
  int dummy;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ asprintf(char **, char *, int);
int /*<<< orphan*/ close(int);
int execv(char *, char **);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
char *strdup(char *);
scalar_t__ wait(int *);
int gpg(char *keys, char *file) {
  int ret = 0, fd = 0, i = 0;
  char cmd[PATH_MAX + 1];
  char *args[512];
  pid_t pid;
  struct stat buf;
  if (stat("/usr/bin/gpgv", &buf))
    return (1);
  if ((fd = open("/dev/null", O_WRONLY)) == -1)
    return (1);
  pid = fork();
  if (pid < 0)
    return (1);
  else if (pid == 0) {
    args[i++] = strdup("gpgv");
    args[i++] = strdup("--logger-fd");
    asprintf(&args[i++], "%d", fd);
    args[i++] = strdup("--keyring");
    args[i++] = keys;
    args[i++] = file;
    ret = execv("/usr/bin/gpgv", args);
    for (i = 0; i < 4; i++)
      free(args[i]);
    exit(ret);
  } else
    while (wait(&ret) != pid)
      ;
  close(fd);
  return (!ret);
}


x86 assembly (clang, -O0):
<gpg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1060,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,-0x38(%rbp)
lea    0xe18(%rip),%rdi
lea    -0x1050(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
je     1214 <gpg+0x74>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1054(%rbp)
jmp    13ee <gpg+0x24e>
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
lea    0xdea(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    124b <gpg+0xab>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1054(%rbp)
jmp    13ee <gpg+0x24e>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x1048(%rbp)
cmpq   $0x0,-0x1048(%rbp)
jge    127d <gpg+0xdd>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x1054(%rbp)
jmp    13ee <gpg+0x24e>
cmpq   $0x0,-0x1048(%rbp)
jne    13a1 <gpg+0x201>
lea    0xd77(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %rcx,-0x1040(%rbp,%rax,8)
ff
lea    0xd62(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %rcx,-0x1040(%rbp,%rax,8)
ff
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
cltq
lea    -0x1040(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%edx
lea    0xd2c(%rip),%rsi
call   1060 <asprintf@plt>
lea    0xd23(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %rcx,-0x1040(%rbp,%rax,8)
ff
mov    -0x10(%rbp),%rcx
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %rcx,-0x1040(%rbp,%rax,8)
ff
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %rcx,-0x1040(%rbp,%rax,8)
ff
lea    -0x1040(%rbp),%rsi
lea    0xc9f(%rip),%rdi
call   10b0 <execv@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1399 <gpg+0x1f9>
movslq -0x24(%rbp),%rax
mov    -0x1040(%rbp,%rax,8),%rdi
ff
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1370 <gpg+0x1d0>
mov    -0x1c(%rbp),%edi
call   1080 <exit@plt>
jmp    13a6 <gpg+0x206>
lea    -0x1c(%rbp),%rdi
call   10a0 <wait@plt>
cmp    -0x1048(%rbp),%rax
je     13c1 <gpg+0x221>
jmp    13a6 <gpg+0x206>
jmp    13c6 <gpg+0x226>
jmp    13cb <gpg+0x22b>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x1054(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%r13
movl   $0x0,0x4(%rsp)
lea    0xe37(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <stat@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11f4 <gpg+0x54>
mov    %r13,%rsp
mov    %ebx,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
lea    0xe0a(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11dd <gpg+0x3d>
mov    %eax,%r12d
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
js     11dd <gpg+0x3d>
je     1251 <gpg+0xb1>
mov    %rax,%rbp
lea    0x4(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <wait@plt>
cmp    %rbp,%rax
jne    1230 <gpg+0x90>
mov    %r12d,%edi
call   1040 <close@plt>
xor    %ebx,%ebx
cmpl   $0x0,0x4(%rsp)
sete   %bl
jmp    11dd <gpg+0x3d>
lea    0xdb1(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,0x10(%rsp)
lea    0xdaf(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,0x18(%rsp)
lea    0x20(%rsp),%rdi
lea    0xda5(%rip),%rsi
mov    %r12d,%edx
call   1060 <asprintf@plt>
lea    0xd99(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,0x28(%rsp)
mov    %r15,0x30(%rsp)
mov    %r14,0x38(%rsp)
lea    0xd57(%rip),%rdi
lea    0x10(%rsp),%rsi
call   10b0 <execv@plt>
mov    %eax,0x4(%rsp)
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x20(%rsp),%rdi
call   1030 <free@plt>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [14 x i8] c"/usr/bin/gpgv\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.2 = [5 x i8] c"gpgv\00"
@.str.3 = [12 x i8] c"--logger-fd\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [10 x i8] c"--keyring\00"
define i32 @gpg(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca [512 x i8*]
%12 = alloca i64
%13 = alloca %struct.stat
%14 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%15 = load i32, i32* @PATH_MAX
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %9
%19 = alloca i8, i64 %17
store i64 %17, i64* %10
%20 = call i64 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %struct.stat* %13)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 1, i32* %3
store i32 1, i32* %14
br label %100
23: ; preds = %2
%24 = load i32, i32* @O_WRONLY
%25 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %24)
store i32 %25, i32* %7
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 1, i32* %3
store i32 1, i32* %14
br label %100
28: ; preds = %23
%29 = call i64 (...) @fork()
store i64 %29, i64* %12
%30 = load i64, i64* %12
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 1, i32* %3
store i32 1, i32* %14
br label %100
33: ; preds = %28
%34 = load i64, i64* %12
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %85
36: ; preds = %33
%37 = call i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds [512 x i8*], [512 x i8*]* %11, i64 0, i64 %40
store i8* %37, i8** %41
%42 = call i8* @strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds [512 x i8*], [512 x i8*]* %11, i64 0, i64 %45
store i8* %42, i8** %46
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds [512 x i8*], [512 x i8*]* %11, i64 0, i64 %49
%51 = load i32, i32* %7
%52 = call i32 @asprintf(i8** %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = call i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%54 = load i32, i32* %8
%55 = add nsw i32 %54, 1
store i32 %55, i32* %8
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds [512 x i8*], [512 x i8*]* %11, i64 0, i64 %56
store i8* %53, i8** %57
%58 = load i8*, i8** %4
%59 = load i32, i32* %8
%60 = add nsw i32 %59, 1
store i32 %60, i32* %8
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds [512 x i8*], [512 x i8*]* %11, i64 0, i64 %61
store i8* %58, i8** %62
%63 = load i8*, i8** %5
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds [512 x i8*], [512 x i8*]* %11, i64 0, i64 %66
store i8* %63, i8** %67
%68 = getelementptr inbounds [512 x i8*], [512 x i8*]* %11, i64 0, i64 0
%69 = call i32 @execv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %68)
store i32 %69, i32* %6
store i32 0, i32* %8
br label %70
70: ; preds = %79, %36
%71 = load i32, i32* %8
%72 = icmp slt i32 %71, 4
br i1 %72, label %73, label %82
73: ; preds = %70
%74 = load i32, i32* %8
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [512 x i8*], [512 x i8*]* %11, i64 0, i64 %75
%77 = load i8*, i8** %76
%78 = call i32 @free(i8* %77)
br label %79
79: ; preds = %73
%80 = load i32, i32* %8
%81 = add nsw i32 %80, 1
store i32 %81, i32* %8
br label %70
82: ; preds = %70
%83 = load i32, i32* %6
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %33
br label %86
86: ; preds = %90, %85
%87 = call i64 @wait(i32* %6)
%88 = load i64, i64* %12
%89 = icmp ne i64 %87, %88
br i1 %89, label %90, label %91
90: ; preds = %86
br label %86
91: ; preds = %86
br label %92
92: ; preds = %91
br label %93
93: ; preds = %92
%94 = load i32, i32* %7
%95 = call i32 @close(i32 %94)
%96 = load i32, i32* %6
%97 = icmp ne i32 %96, 0
%98 = xor i1 %97, true
%99 = zext i1 %98 to i32
store i32 %99, i32* %3
store i32 1, i32* %14
br label %100
100: ; preds = %93, %32, %27, %22
%101 = load i8*, i8** %9
%102 = load i32, i32* %3
ret i32 %102
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [14 x i8] c"/usr/bin/gpgv\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.2 = [5 x i8] c"gpgv\00"
@.str.3 = [12 x i8] c"--logger-fd\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [10 x i8] c"--keyring\00"
define i32 @gpg(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca [512 x i8*]
%5 = alloca %struct.stat
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = tail call i8* @llvm.stacksave()
%8 = bitcast [512 x i8*]* %4 to i8*
%9 = bitcast %struct.stat* %5 to i8*
%10 = call i64 @stat(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %struct.stat* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %51
12: ; preds = %2
%13 = load i32, i32* @O_WRONLY
%14 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %51, label %16
16: ; preds = %12
%17 = call i64 (...) @fork()
%18 = icmp slt i64 %17, 0
br i1 %18, label %51, label %19
19: ; preds = %16
%20 = icmp eq i64 %17, 0
br i1 %20, label %21, label %43
21: ; preds = %19
%22 = call dereferenceable_or_null(5) i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds [512 x i8*], [512 x i8*]* %4, i64 0, i64 0
store i8* %22, i8** %23
%24 = call dereferenceable_or_null(12) i8* @strdup(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds [512 x i8*], [512 x i8*]* %4, i64 0, i64 1
store i8* %24, i8** %25
%26 = getelementptr inbounds [512 x i8*], [512 x i8*]* %4, i64 0, i64 2
%27 = call i32 @asprintf(i8** %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%28 = call dereferenceable_or_null(10) i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%29 = getelementptr inbounds [512 x i8*], [512 x i8*]* %4, i64 0, i64 3
store i8* %28, i8** %29
%30 = getelementptr inbounds [512 x i8*], [512 x i8*]* %4, i64 0, i64 4
store i8* %0, i8** %30
%31 = getelementptr inbounds [512 x i8*], [512 x i8*]* %4, i64 0, i64 5
store i8* %1, i8** %31
%32 = call i32 @execv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %23)
store i32 %32, i32* %3
%33 = load i8*, i8** %23
%34 = call i32 @free(i8* %33)
%35 = load i8*, i8** %25
%36 = call i32 @free(i8* %35)
%37 = load i8*, i8** %26
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %29
%40 = call i32 @free(i8* %39)
%41 = load i32, i32* %3
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %19, %43
%44 = call i64 @wait(i32* %3)
%45 = icmp eq i64 %44, %17
br i1 %45, label %46, label %43
46: ; preds = %43
%47 = call i32 @close(i32 %14)
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, 0
%50 = zext i1 %49 to i32
br label %51
51: ; preds = %16, %12, %2, %46
%52 = phi i32 [ %50, %46 ], [ 1, %2 ], [ 1, %12 ], [ 1, %16 ]
ret i32 %52
}