#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 *);
char *malloc(int);
int /*<<< orphan*/ sm_add_part(char *, char *, int);
char *sm_getenv(char *);
int sm_system(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int pgp_operate(char *options, char *output) {
  char *path = sm_getenv("PGPPATH");
  int len =
      ((path) ? strlen(path) : 0) + 10 + ((options) ? strlen(options) : 0);
  int rc;
  char *buf = 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 i8* @malloc(i32 %30)
store i8* %31, i8** %9
%32 = load i8*, i8** %9
%33 = icmp ne i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %27
store i32 0, i32* %3
br label %70
35: ; preds = %27
%36 = load i8*, i8** %6
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = load i8*, i8** %9
%40 = load i8*, i8** %6
%41 = call i32 @strcpy(i8* %39, i8* %40)
br label %45
42: ; preds = %35
%43 = load i8*, i8** %9
%44 = getelementptr inbounds i8, i8* %43, i64 0
store i8 0, i8* %44
br label %45
45: ; preds = %42, %38
%46 = load i8*, i8** %9
%47 = load i32, i32* %7
%48 = call i32 @sm_add_part(i8* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = load i8*, i8** %9
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %50, i32** %10
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %57
52: ; preds = %45
%53 = load i32*, i32** %10
%54 = call i32 @fclose(i32* %53)
%55 = load i8*, i8** %9
%56 = call i32 @strcat(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %60
57: ; preds = %45
%58 = load i8*, i8** %9
%59 = call i32 @strcpy(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %57, %52
%61 = load i8*, i8** %9
%62 = load i8*, i8** %4
%63 = call i32 @strcat(i8* %61, i8* %62)
%64 = load i8*, i8** %9
%65 = load i8*, i8** %5
%66 = call i32 @sm_system(i8* %64, i8* %65)
store i32 %66, i32* %8
%67 = load i8*, i8** %9
%68 = call i32 @free(i8* %67)
%69 = load i32, i32* %8
store i32 %69, i32* %3
br label %70
70: ; preds = %60, %34
%71 = load i32, i32* %3
ret i32 %71
}

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 i8* @malloc(i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %35, label %18
18: ; preds = %13
br i1 %4, label %21, label %19
19: ; preds = %18
%20 = tail call i32 @strcpy(i8* %16, i8* %3)
br label %22
21: ; preds = %18
store i8 0, i8* %16
br label %22
22: ; preds = %21, %19
%23 = tail call i32 @sm_add_part(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%24 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %29, label %26
26: ; preds = %22
%27 = tail call i32 @fclose(i32* %24)
%28 = tail call i32 @strcat(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %31
29: ; preds = %22
%30 = tail call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
%32 = tail call i32 @strcat(i8* %16, i8* %0)
%33 = tail call i32 @sm_system(i8* %16, i8* %1)
%34 = tail call i32 @free(i8* %16)
br label %35
35: ; preds = %13, %31
%36 = phi i32 [ %33, %31 ], [ 0, %13 ]
ret i32 %36
}