#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ succeed_if(int, char *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int /*<<< orphan*/ yield_error(char *);
void test_teardown(void) {
  pid_t pid;
  int status;
  char *argv[] = {"gpg-connect-agent", "--quiet", "KILLAGENT", "/bye", NULL};
  if (access("gpg-connect-agent", F_OK)) {
    return;
  }
  if (access("gpg-connect-agent", X_OK)) {
    return;
  }
  switch (pid = fork()) {
  case -1:
    yield_error("fork failed");
    return;
  case 0:
    if (execv("gpg-connect-agent", argv) < 0) {
      exit(-1);
    }
  }
  waitpid(pid, &status, 0);
  succeed_if(status != -1, "failed to execute gpg-connect-agent");
  if (status > 0) {
    pid = status;
    waitpid(pid, &status, 0);
  }
}


x86 assembly (clang, -O0):
<test_teardown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
lea    0xe96(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe56(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe53(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe52(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
je     11e8 <test_teardown+0x68>
jmp    12b6 <test_teardown+0x136>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    0xe3d(%rip),%rdi
call   1070 <access@plt>
cmp    $0x0,%rax
je     120c <test_teardown+0x8c>
jmp    12b6 <test_teardown+0x136>
xor    %eax,%eax
call   10a0 <fork@plt>
mov    %eax,-0x4(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
sub    $0xffffffff,%eax
je     1239 <test_teardown+0xb9>
jmp    1229 <test_teardown+0xa9>
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     124a <test_teardown+0xca>
jmp    1272 <test_teardown+0xf2>
lea    0xdd7(%rip),%rdi
call   1050 <yield_error@plt>
jmp    12b6 <test_teardown+0x136>
lea    -0x30(%rbp),%rsi
lea    0xde0(%rip),%rdi
call   1090 <execv@plt>
cmp    $0x0,%eax
jge    126d <test_teardown+0xed>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    1272 <test_teardown+0xf2>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
cmpl   $0xffffffff,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xd90(%rip),%rsi
call   1040 <succeed_if@plt>
cmpl   $0x0,-0x8(%rbp)
jle    12b6 <test_teardown+0x136>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_teardown>:
push   %rbx
sub    $0x40,%rsp
movq   $0x0,0x30(%rsp)
lea    0xeb0(%rip),%rdi
mov    %rdi,0x10(%rsp)
lea    0xe6f(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe6b(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe69(%rip),%rax
mov    %rax,0x28(%rsp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
test   %rax,%rax
jne    11db <test_teardown+0x6b>
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
je     11e1 <test_teardown+0x71>
add    $0x40,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1204 <test_teardown+0x94>
cmp    $0xffffffff,%ebx
jne    1219 <test_teardown+0xa9>
lea    0xe1d(%rip),%rdi
add    $0x40,%rsp
pop    %rbx
jmp    1040 <yield_error@plt>
lea    0xe2a(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1080 <execv@plt>
test   %eax,%eax
js     1254 <test_teardown+0xe4>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
xor    %edi,%edi
cmpl   $0xffffffff,0xc(%rsp)
setne  %dil
lea    0xdea(%rip),%rsi
call   1030 <succeed_if@plt>
mov    0xc(%rsp),%edi
test   %edi,%edi
jle    11db <test_teardown+0x6b>
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
jmp    11db <test_teardown+0x6b>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"gpg-connect-agent\00"
@.str.1 = [8 x i8] c"--quiet\00"
@.str.2 = [10 x i8] c"KILLAGENT\00"
@.str.3 = [5 x i8] c"/bye\00"
@F_OK = global i32 0
@X_OK = global i32 0
@.str.4 = [12 x i8] c"fork failed\00"
@.str.5 = [36 x i8] c"failed to execute gpg-connect-agent\00"
define void @test_teardown() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5 x i8*]
%4 = bitcast [5 x i8*]* %3 to i8*
%5 = bitcast i8* %4 to [5 x i8*]*
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i32 0, i32 0
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i32 0, i32 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i32 0, i32 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i32 0, i32 2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i32 0, i32 3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8** %9
%10 = load i32, i32* @F_OK
%11 = call i64 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %0
br label %43
14: ; preds = %0
%15 = load i32, i32* @X_OK
%16 = call i64 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
br label %43
19: ; preds = %14
%20 = call i32 (...) @fork()
store i32 %20, i32* %1
switch i32 %20, label %30 [
i32 -1, label %21
i32 0, label %23
]
21: ; preds = %19
%22 = call i32 @yield_error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %43
23: ; preds = %19
%24 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
%25 = call i32 @execv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %23
br label %30
30: ; preds = %29, %19
%31 = load i32, i32* %1
%32 = call i32 @waitpid(i32 %31, i32* %2, i32 0)
%33 = load i32, i32* %2
%34 = icmp ne i32 %33, -1
%35 = zext i1 %34 to i32
%36 = call i32 @succeed_if(i32 %35, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%37 = load i32, i32* %2
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %30
%40 = load i32, i32* %2
store i32 %40, i32* %1
%41 = load i32, i32* %1
%42 = call i32 @waitpid(i32 %41, i32* %2, i32 0)
br label %43
43: ; preds = %13, %18, %21, %39, %30
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"gpg-connect-agent\00"
@.str.1 = [8 x i8] c"--quiet\00"
@.str.2 = [10 x i8] c"KILLAGENT\00"
@.str.3 = [5 x i8] c"/bye\00"
@F_OK = global i32 0
@X_OK = global i32 0
@.str.4 = [12 x i8] c"fork failed\00"
@.str.5 = [36 x i8] c"failed to execute gpg-connect-agent\00"
define void @test_teardown() {
%1 = alloca i32
%2 = alloca [5 x i8*]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [5 x i8*]* %2 to i8*
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 4
%6 = bitcast i8** %5 to i64*
store i64 0, i64* %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %10
%11 = load i32, i32* @F_OK
%12 = tail call i64 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %37
14: ; preds = %0
%15 = load i32, i32* @X_OK
%16 = tail call i64 @access(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = tail call i32 (...) @fork()
switch i32 %19, label %27 [
i32 -1, label %20
i32 0, label %22
]
20: ; preds = %18
%21 = tail call i32 @yield_error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %37
22: ; preds = %18
%23 = call i32 @execv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8** %7)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %22, %18
%28 = call i32 @waitpid(i32 %19, i32* %1, i32 0)
%29 = load i32, i32* %1
%30 = icmp ne i32 %29, -1
%31 = zext i1 %30 to i32
%32 = call i32 @succeed_if(i32 %31, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%33 = load i32, i32* %1
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %27
%36 = call i32 @waitpid(i32 %33, i32* %1, i32 0)
br label %37
37: ; preds = %27, %35, %14, %0, %20
ret void
}