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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ system(char *);
int main(int argc, char *argv[]) {
  char buf[16];
  char command[120];
  int fp, mailnb, sdmail, gpict;
  sdmail = 0;
  gpict = 0;
  while ((argc > 1) && (argv[1][0] == '-')) {
    switch (argv[1][1]) {
    case 's':
      sdmail = 1;
      break;
    case 'p':
      gpict = 1;
      break;
    default:
      printf("Wrong Argument: %s\n", argv[1]);
    }
    ++argv;
    --argc;
  }
  mailnb = 0;
  memset(buf, 0, 16);
  fp = open("/dev/pir_sensor", O_RDONLY);
  if (fp < 0) {
    perror("pir-sensor-app: open() pir-sensor driver failed: reason ");
    exit(-1);
  }
  while (1) {
    if (read(fp, buf, 16) < 0) {
      perror("pir-sensor-app: read() pir-sensor driver failed: reason ");
      exit(-1);
    }
    if (sdmail) {
      strcpy(command, "echo \"<your_message>\" | mail -s \"<your_mail_head>\" "
                      "<your.mail@yourmail.com");
      if (system(command) < 0) {
        fprintf(stderr, "pir-sensor-app: system() failed to send mail");
        exit(-1);
      }
      mailnb++;
    }
    if (gpict) {
      strcpy(command,
             "sudo raspistill -h 680 -w 1024 -q 100 -o /var/www/picture.jpg");
      if (system(command) < 0) {
        fprintf(stderr, "pir-sensor-app: system() failed to take picture.");
        exit(-1);
      }
    }
    memset(buf, 0, 16);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xac(%rbp)
movl   $0x0,-0xb0(%rbp)
xor    %eax,%eax
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0xb1(%rbp)
jle    11e6 <main+0x56>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0xb1(%rbp)
mov    -0xb1(%rbp),%al
test   $0x1,%al
jne    11f9 <main+0x69>
jmp    1279 <main+0xe9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0xb8(%rbp)
sub    $0x70,%eax
je     123c <main+0xac>
jmp    1219 <main+0x89>
mov    -0xb8(%rbp),%eax
sub    $0x73,%eax
jne    124b <main+0xbb>
jmp    122d <main+0x9d>
movl   $0x1,-0xac(%rbp)
jmp    125f <main+0xcf>
movl   $0x1,-0xb0(%rbp)
jmp    125f <main+0xcf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xda6(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11bd <main+0x2d>
movl   $0x0,-0xa8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
lea    0xd71(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jge    12d1 <main+0x141>
lea    0xd62(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
jmp    12d6 <main+0x146>
mov    -0xa4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jge    130a <main+0x17a>
lea    0xd62(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0xac(%rbp)
je     136e <main+0x1de>
lea    -0xa0(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <system@plt>
cmp    $0x0,%rax
jge    135f <main+0x1cf>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0xa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa8(%rbp)
cmpl   $0x0,-0xb0(%rbp)
je     13c8 <main+0x238>
lea    -0xa0(%rbp),%rdi
lea    0xd85(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <system@plt>
cmp    $0x0,%rax
jge    13c3 <main+0x233>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0xd98(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
jmp    13c8 <main+0x238>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
jmp    12d6 <main+0x146>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
xor    %r12d,%r12d
mov    $0x0,%r13d
cmp    $0x2,%edi
jl     1218 <main+0x88>
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0x1,%ebp
add    $0x8,%rbx
xor    %r13d,%r13d
lea    0xe3b(%rip),%r14
xor    %r12d,%r12d
jmp    11e4 <main+0x54>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <printf@plt>
add    $0xffffffff,%ebp
add    $0x8,%rbx
cmp    $0x2,%ebp
jle    1218 <main+0x88>
mov    (%rbx),%rsi
cmpb   $0x2d,(%rsi)
jne    1218 <main+0x88>
movsbl 0x1(%rsi),%eax
cmp    $0x73,%eax
je     1210 <main+0x80>
cmp    $0x70,%eax
jne    11d0 <main+0x40>
mov    $0x1,%r13d
jmp    11d8 <main+0x48>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%r12d
jmp    11d8 <main+0x48>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
lea    0xddd(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
jns    1249 <main+0xb9>
lea    0xddd(%rip),%rdi
jmp    1267 <main+0xd7>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1070 <read@plt>
test   %rax,%rax
jns    1276 <main+0xe6>
lea    0xdf6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    %rsp,%rbp
lea    0x10(%rsp),%rbx
lea    0xe11(%rip),%r14
jmp    12b4 <main+0x124>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x10,%edx
call   1070 <read@plt>
test   %rax,%rax
js     1260 <main+0xd0>
test   %r12d,%r12d
je     12d1 <main+0x141>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
test   %rax,%rax
js     1304 <main+0x174>
test   %r13d,%r13d
je     1290 <main+0x100>
mov    %rbx,%rdi
lea    0xe2e(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
test   %rax,%rax
jns    1290 <main+0x100>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
jmp    1314 <main+0x184>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Wrong Argument: %s\0A\00"
@.str.1 = [16 x i8] c"/dev/pir_sensor\00"
@O_RDONLY = global i32 0
@.str.2 = [57 x i8] c"pir-sensor-app: open() pir-sensor driver failed: reason \00"
@.str.3 = [57 x i8] c"pir-sensor-app: read() pir-sensor driver failed: reason \00"
@.str.4 = [75 x i8] c"echo \22<your_message>\22 | mail -s \22<your_mail_head>\22 <your.mail@yourmail.com\00"
@stderr = global i32 0
@.str.5 = [45 x i8] c"pir-sensor-app: system() failed to send mail\00"
@.str.6 = [62 x i8] c"sudo raspistill -h 680 -w 1024 -q 100 -o /var/www/picture.jpg\00"
@.str.7 = [49 x i8] c"pir-sensor-app: system() failed to take picture.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [16 x i8]
%7 = alloca [120 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %11
br label %12
12: ; preds = %39, %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 45
br label %23
23: ; preds = %15, %12
%24 = phi i1 [ false, %12 ], [ %22, %15 ]
br i1 %24, label %25, label %44
25: ; preds = %23
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
switch i32 %31, label %34 [
i32 115, label %32
i32 112, label %33
]
32: ; preds = %25
store i32 1, i32* %10
br label %39
33: ; preds = %25
store i32 1, i32* %11
br label %39
34: ; preds = %25
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %34, %33, %32
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i32 1
store i8** %41, i8*** %5
%42 = load i32, i32* %4
%43 = add nsw i32 %42, -1
store i32 %43, i32* %4
br label %12
44: ; preds = %23
store i32 0, i32* %9
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%46 = call i32 @memset(i8* %45, i32 0, i32 16)
%47 = load i32, i32* @O_RDONLY
%48 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %47)
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %44
%52 = call i32 @perror(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %44
br label %55
55: ; preds = %54, %93
%56 = load i32, i32* %8
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%58 = call i64 @read(i32 %56, i8* %57, i32 16)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %55
%61 = call i32 @perror(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
%62 = call i32 @exit(i32 -1)
unreachable
63: ; preds = %55
%64 = load i32, i32* %10
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %79
66: ; preds = %63
%67 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%68 = call i32 @strcpy(i8* %67, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
%69 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%70 = call i64 @system(i8* %69)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %66
%73 = load i32, i32* @stderr
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @exit(i32 -1)
unreachable
76: ; preds = %66
%77 = load i32, i32* %9
%78 = add nsw i32 %77, 1
store i32 %78, i32* %9
br label %79
79: ; preds = %76, %63
%80 = load i32, i32* %11
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %93
82: ; preds = %79
%83 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%84 = call i32 @strcpy(i8* %83, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0))
%85 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%86 = call i64 @system(i8* %85)
%87 = icmp slt i64 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %82
%89 = load i32, i32* @stderr
%90 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%91 = call i32 @exit(i32 -1)
unreachable
92: ; preds = %82
br label %93
93: ; preds = %92, %79
%94 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%95 = call i32 @memset(i8* %94, i32 0, i32 16)
br label %55
}

LLVM IR (-O2):
@.str = [20 x i8] c"Wrong Argument: %s\0A\00"
@.str.1 = [16 x i8] c"/dev/pir_sensor\00"
@O_RDONLY = global i32 0
@.str.2 = [57 x i8] c"pir-sensor-app: open() pir-sensor driver failed: reason \00"
@.str.3 = [57 x i8] c"pir-sensor-app: read() pir-sensor driver failed: reason \00"
@.str.4 = [75 x i8] c"echo \22<your_message>\22 | mail -s \22<your_mail_head>\22 <your.mail@yourmail.com\00"
@stderr = global i32 0
@.str.5 = [45 x i8] c"pir-sensor-app: system() failed to send mail\00"
@.str.6 = [62 x i8] c"sudo raspistill -h 680 -w 1024 -q 100 -o /var/www/picture.jpg\00"
@.str.7 = [49 x i8] c"pir-sensor-app: system() failed to take picture.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [16 x i8]
%4 = alloca [120 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [120 x i8], [120 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %29
8: ; preds = %2, %24
%9 = phi i32 [ %26, %24 ], [ 0, %2 ]
%10 = phi i32 [ %25, %24 ], [ 0, %2 ]
%11 = phi i32 [ %27, %24 ], [ %0, %2 ]
%12 = phi i8** [ %13, %24 ], [ %1, %2 ]
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 45
br i1 %16, label %17, label %29
17: ; preds = %8
%18 = getelementptr inbounds i8, i8* %14, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
switch i32 %20, label %22 [
i32 115, label %24
i32 112, label %21
]
21: ; preds = %17
br label %24
22: ; preds = %17
%23 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %24
24: ; preds = %17, %22, %21
%25 = phi i32 [ %10, %22 ], [ %10, %21 ], [ 1, %17 ]
%26 = phi i32 [ %9, %22 ], [ 1, %21 ], [ %9, %17 ]
%27 = add nsw i32 %11, -1
%28 = icmp sgt i32 %11, 2
br i1 %28, label %8, label %29
29: ; preds = %8, %24, %2
%30 = phi i32 [ 0, %2 ], [ %25, %24 ], [ %10, %8 ]
%31 = phi i32 [ 0, %2 ], [ %26, %24 ], [ %9, %8 ]
%32 = call i32 @memset(i8* %5, i32 0, i32 16)
%33 = load i32, i32* @O_RDONLY
%34 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = icmp slt i32 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %29
%37 = call i64 @read(i32 %34, i8* %5, i32 16)
%38 = icmp slt i64 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %36
%40 = icmp eq i32 %30, 0
%41 = icmp eq i32 %31, 0
br label %48
42: ; preds = %29
%43 = call i32 @perror(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %66, %36
%46 = call i32 @perror(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 -1)
unreachable
48: ; preds = %39, %66
br i1 %40, label %57, label %49
49: ; preds = %48
%50 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0))
%51 = call i64 @system(i8* %6)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0))
%56 = call i32 @exit(i32 -1)
unreachable
57: ; preds = %49, %48
br i1 %41, label %66, label %58
58: ; preds = %57
%59 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0))
%60 = call i64 @system(i8* %6)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %58, %57
%67 = call i32 @memset(i8* %5, i32 0, i32 16)
%68 = call i64 @read(i32 %34, i8* %5, i32 16)
%69 = icmp slt i64 %68, 0
br i1 %69, label %45, label %48
}