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

/* Variables and functions */
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ execlp(char *, char *, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ wait(int *);
int test_camera(void) {
  int status;
  pid_t pid;
  pid = fork();
  if (pid == 0) {
    close(1);
    close(2);
    execlp("raspistill", "raspistill", "-t", "30", NULL);
    exit(70);
  }
  wait(&status);
  if (!WIFEXITED(status))
    return 0;
  if (WEXITSTATUS(status) != 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<test_camera>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ce <test_camera+0x5e>
mov    $0x1,%edi
call   1030 <close@plt>
mov    $0x2,%edi
call   1030 <close@plt>
lea    0xe57(%rip),%rsi
lea    0xe5b(%rip),%rdx
lea    0xe57(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1070 <execlp@plt>
mov    $0x46,%edi
call   1060 <exit@plt>
lea    -0x8(%rbp),%rdi
call   1080 <wait@plt>
mov    -0x8(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    11f4 <test_camera+0x84>
movl   $0x0,-0x4(%rbp)
jmp    1219 <test_camera+0xa9>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1212 <test_camera+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    1219 <test_camera+0xa9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_camera>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11b3 <test_camera+0x43>
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
mov    0xc(%rsp),%edi
call   1050 <WIFEXITED@plt>
test   %eax,%eax
je     11ab <test_camera+0x3b>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x1,%edi
call   1030 <close@plt>
mov    $0x2,%edi
call   1030 <close@plt>
lea    0xe32(%rip),%rdi
lea    0xe36(%rip),%rdx
lea    0xe32(%rip),%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
call   1070 <execlp@plt>
mov    $0x46,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"raspistill\00"
@.str.1 = [3 x i8] c"-t\00"
@.str.2 = [3 x i8] c"30\00"
define i32 @test_camera() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = call i64 (...) @fork()
store i64 %4, i64* %3
%5 = load i64, i64* %3
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = call i32 @close(i32 1)
%9 = call i32 @close(i32 2)
%10 = call i32 @execlp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* null)
%11 = call i32 @exit(i32 70)
unreachable
12: ; preds = %0
%13 = call i32 @wait(i32* %2)
%14 = load i32, i32* %2
%15 = call i32 @WIFEXITED(i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %12
store i32 0, i32* %1
br label %24
18: ; preds = %12
%19 = load i32, i32* %2
%20 = call i64 @WEXITSTATUS(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 0, i32* %1
br label %24
23: ; preds = %18
store i32 1, i32* %1
br label %24
24: ; preds = %23, %22, %17
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [11 x i8] c"raspistill\00"
@.str.1 = [3 x i8] c"-t\00"
@.str.2 = [3 x i8] c"30\00"
define i32 @test_camera() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = tail call i32 @close(i32 1)
%7 = tail call i32 @close(i32 2)
%8 = tail call i32 @execlp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* null)
%9 = tail call i32 @exit(i32 70)
unreachable
10: ; preds = %0
%11 = call i32 @wait(i32* %1)
%12 = load i32, i32* %1
%13 = call i32 @WIFEXITED(i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = load i32, i32* %1
%17 = call i64 @WEXITSTATUS(i32 %16)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %15, %10
%21 = phi i32 [ 0, %10 ], [ %19, %15 ]
ret i32 %21
}