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

/* Variables and functions */
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ errno;
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int /*<<< orphan*/ write_log(int, char *, ...);
int call_lp(char **argv) {
  int status;
  pid_t pid = fork();
  if (!pid) {
    if (execvp("lp", argv)) {
      write_log(2, "Call to lp failed: %s", strerror(errno));
      return -1;
    }
    return 0;
  }
  waitpid(pid, &status, 0);
  if (!WIFEXITED(status) || WEXITSTATUS(status)) {
    write_log(2, "lp exited abnormally.");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<call_lp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11e5 <call_lp+0x75>
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdi
call   1060 <execvp@plt>
cmp    $0x0,%rax
je     11d9 <call_lp+0x69>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1030 <write_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <call_lp+0xcc>
movl   $0x0,-0x4(%rbp)
jmp    123c <call_lp+0xcc>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x14(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%eax
je     1216 <call_lp+0xa6>
mov    -0x14(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1235 <call_lp+0xc5>
mov    $0x2,%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1030 <write_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <call_lp+0xcc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<call_lp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11c4 <call_lp+0x54>
lea    0x4(%rsp),%rsi
xor    %ebx,%ebx
mov    %eax,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %eax,%eax
je     11af <call_lp+0x3f>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
test   %rax,%rax
je     1200 <call_lp+0x90>
lea    0xe63(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1030 <write_log@plt>
jmp    11fb <call_lp+0x8b>
lea    0xe35(%rip),%rdi
mov    %r14,%rsi
call   1060 <execvp@plt>
test   %rax,%rax
je     1200 <call_lp+0x90>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe16(%rip),%rsi
mov    $0x2,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write_log@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"lp\00"
@.str.1 = [22 x i8] c"Call to lp failed: %s\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"lp exited abnormally.\00"
define i32 @call_lp(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %3
%6 = call i32 (...) @fork()
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %1
%10 = load i8**, i8*** %3
%11 = call i64 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 (i32, i8*, ...) @write_log(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 -1, i32* %2
br label %31
17: ; preds = %9
store i32 0, i32* %2
br label %31
18: ; preds = %1
%19 = load i32, i32* %5
%20 = call i32 @waitpid(i32 %19, i32* %4, i32 0)
%21 = load i32, i32* %4
%22 = call i32 @WIFEXITED(i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i32, i32* %4
%26 = call i64 @WEXITSTATUS(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24, %18
%29 = call i32 (i32, i8*, ...) @write_log(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %31
30: ; preds = %24
store i32 0, i32* %2
br label %31
31: ; preds = %30, %28, %17, %13
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@.str = [3 x i8] c"lp\00"
@.str.1 = [22 x i8] c"Call to lp failed: %s\00"
@errno = global i32 0
@.str.2 = [22 x i8] c"lp exited abnormally.\00"
define i32 @call_lp(i8** %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = tail call i64 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %6
%10 = load i32, i32* @errno
%11 = tail call i32 @strerror(i32 %10)
%12 = tail call i32 (i32, i8*, ...) @write_log(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %24
13: ; preds = %1
%14 = call i32 @waitpid(i32 %4, i32* %2, i32 0)
%15 = load i32, i32* %2
%16 = call i32 @WIFEXITED(i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load i32, i32* %2
%20 = call i64 @WEXITSTATUS(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18, %13
%23 = call i32 (i32, i8*, ...) @write_log(i32 2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %18, %6, %22, %9
%25 = phi i32 [ -1, %22 ], [ -1, %9 ], [ 0, %6 ], [ 0, %18 ]
ret i32 %25
}