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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sm_add_part(char *, char *, int);
char *sm_getenv(char *);
int sm_system(char *, char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
int pgp_operate(const char *options, char *output) {
  char *path = sm_getenv("PGPPATH");
  int len =
      ((path) ? strlen(path) : 0) + 10 + ((options) ? strlen(options) : 0);
  int rc;
  char *buf = (char *)malloc(len);
  FILE *fh;
  if (!buf)
    return 0;
  if (path)
    strcpy(buf, path);
  else
    buf[0] = 0;
  sm_add_part(buf, "pgp", len);
  if ((fh = fopen(buf, "rb"))) {
    fclose(fh);
    strcat(buf, " ");
  } else
    strcpy(buf, "pgp ");
  strcat(buf, options);
  rc = sm_system(buf, output);
  free(buf);
  return rc;
}


x86 assembly (clang, -O0):
<pgp_operate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe49(%rip),%rdi
call   10c0 <sm_getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11dc <pgp_operate+0x3c>
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x3c(%rbp)
jmp    11e6 <pgp_operate+0x46>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e6 <pgp_operate+0x46>
mov    -0x3c(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     120b <pgp_operate+0x6b>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x44(%rbp)
jmp    1215 <pgp_operate+0x75>
xor    %eax,%eax
mov    %eax,-0x44(%rbp)
jmp    1215 <pgp_operate+0x75>
mov    -0x40(%rbp),%eax
mov    -0x44(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1243 <pgp_operate+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    12f2 <pgp_operate+0x152>
cmpq   $0x0,-0x20(%rbp)
je     1260 <pgp_operate+0xc0>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcpy@plt>
jmp    1267 <pgp_operate+0xc7>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xd93(%rip),%rsi
call   1040 <sm_add_part@plt>
mov    -0x30(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12b6 <pgp_operate+0x116>
mov    -0x38(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x30(%rbp),%rdi
lea    0xd66(%rip),%rsi
call   10b0 <strcat@plt>
jmp    12c6 <pgp_operate+0x126>
mov    -0x30(%rbp),%rdi
lea    0xd4e(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <sm_system@plt>
mov    %eax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgp_operate>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe4b(%rip),%rdi
call   10c0 <sm_getenv@plt>
mov    %rax,%r12
test   %rax,%rax
je     11e0 <pgp_operate+0x40>
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
add    $0xa,%ebx
test   %r15,%r15
je     11ea <pgp_operate+0x4a>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
jmp    11ec <pgp_operate+0x4c>
mov    $0xa,%ebx
test   %r15,%r15
jne    11d4 <pgp_operate+0x34>
xor    %ebp,%ebp
add    %ebx,%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     120f <pgp_operate+0x6f>
mov    %rax,%rbx
test   %r12,%r12
je     1213 <pgp_operate+0x73>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcpy@plt>
jmp    1216 <pgp_operate+0x76>
xor    %eax,%eax
jmp    1285 <pgp_operate+0xe5>
movb   $0x0,(%rbx)
lea    0xdeb(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <sm_add_part@plt>
lea    0xdde(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1254 <pgp_operate+0xb4>
mov    %rax,%rdi
call   1060 <fclose@plt>
lea    0xdc8(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
jmp    1263 <pgp_operate+0xc3>
lea    0xdb4(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <sm_system@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"PGPPATH\00"
@.str.1 = [4 x i8] c"pgp\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [5 x i8] c"pgp \00"
define i32 @pgp_operate(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = call i8* @sm_getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
br label %18
17: ; preds = %2
br label %18
18: ; preds = %17, %14
%19 = phi i32 [ %16, %14 ], [ 0, %17 ]
%20 = add nsw i32 %19, 10
%21 = load i8*, i8** %4
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
br label %27
26: ; preds = %18
br label %27
27: ; preds = %26, %23
%28 = phi i32 [ %25, %23 ], [ 0, %26 ]
%29 = add nsw i32 %20, %28
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = call i64 @malloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %9
%33 = load i8*, i8** %9
%34 = icmp ne i8* %33, null
br i1 %34, label %36, label %35
35: ; preds = %27
store i32 0, i32* %3
br label %71
36: ; preds = %27
%37 = load i8*, i8** %6
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i8*, i8** %9
%41 = load i8*, i8** %6
%42 = call i32 @strcpy(i8* %40, i8* %41)
br label %46
43: ; preds = %36
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i64 0
store i8 0, i8* %45
br label %46
46: ; preds = %43, %39
%47 = load i8*, i8** %9
%48 = load i32, i32* %7
%49 = call i32 @sm_add_part(i8* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = load i8*, i8** %9
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %51, i32** %10
%52 = icmp ne i32* %51, null
br i1 %52, label %53, label %58
53: ; preds = %46
%54 = load i32*, i32** %10
%55 = call i32 @fclose(i32* %54)
%56 = load i8*, i8** %9
%57 = call i32 @strcat(i8* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %61
58: ; preds = %46
%59 = load i8*, i8** %9
%60 = call i32 @strcpy(i8* %59, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %58, %53
%62 = load i8*, i8** %9
%63 = load i8*, i8** %4
%64 = call i32 @strcat(i8* %62, i8* %63)
%65 = load i8*, i8** %9
%66 = load i8*, i8** %5
%67 = call i32 @sm_system(i8* %65, i8* %66)
store i32 %67, i32* %8
%68 = load i8*, i8** %9
%69 = call i32 @free(i8* %68)
%70 = load i32, i32* %8
store i32 %70, i32* %3
br label %71
71: ; preds = %61, %35
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [8 x i8] c"PGPPATH\00"
@.str.1 = [4 x i8] c"pgp\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [5 x i8] c"pgp \00"
define i32 @pgp_operate(i8* %0, i8* %1) {
%3 = tail call i8* @sm_getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %3)
%7 = add i32 %6, 10
br label %8
8: ; preds = %2, %5
%9 = phi i32 [ %7, %5 ], [ 10, %2 ]
%10 = icmp eq i8* %0, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @strlen(i8* %0)
br label %13
13: ; preds = %8, %11
%14 = phi i32 [ %12, %11 ], [ 0, %8 ]
%15 = add nsw i32 %14, %9
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %36, label %19
19: ; preds = %13
br i1 %4, label %22, label %20
20: ; preds = %19
%21 = tail call i32 @strcpy(i8* %17, i8* %3)
br label %23
22: ; preds = %19
store i8 0, i8* %17
br label %23
23: ; preds = %22, %20
%24 = tail call i32 @sm_add_part(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%25 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %23
%28 = tail call i32 @fclose(i32* %25)
%29 = tail call i32 @strcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %32
30: ; preds = %23
%31 = tail call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
%33 = tail call i32 @strcat(i8* %17, i8* %0)
%34 = tail call i32 @sm_system(i8* %17, i8* %1)
%35 = tail call i32 @free(i8* %17)
br label %36
36: ; preds = %13, %32
%37 = phi i32 [ %34, %32 ], [ 0, %13 ]
ret i32 %37
}