#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*/ activatePhone();
int /*<<< orphan*/ closePhone();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ makeCall(char *);
int /*<<< orphan*/ openPhone(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usage(char *);
int main(int ac, char **av) {
  ;
  if (ac != 3) {
    usage(av[0]);
    printf("Invalid number of arguments: %d\n", ac);
    exit(0);
  }
  if (!openPhone(av[1], "telit")) {
    printf("Cannot open device for the phone\n");
    exit(-1);
  }
  if (!activatePhone()) {
    printf("Cannot activate phone\n");
    closePhone();
    exit(-1);
  }
  printf("Placing a call to: %s\n", av[2]);
  if (!makeCall(av[2])) {
    printf("Jenny's not home\n");
    closePhone();
    exit(-1);
  }
  printf("Jenny is home!\n");
  closePhone();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    -0x8(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1050 <openPhone@plt>
cmp    $0x0,%eax
jne    11e9 <main+0x79>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1030 <activatePhone@plt>
cmp    $0x0,%eax
jne    1218 <main+0xa8>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <closePhone@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <makeCall@plt>
cmp    $0x0,%eax
jne    1263 <main+0xf3>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <closePhone@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <closePhone@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11b5 <main+0x35>
mov    0x8(%rbx),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <openPhone@plt>
test   %eax,%eax
jne    11d6 <main+0x56>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %edi,%ebp
mov    (%rbx),%rdi
call   1080 <usage@plt>
lea    0xe3a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
call   1040 <activatePhone@plt>
test   %eax,%eax
jne    11ea <main+0x6a>
lea    0xe77(%rip),%rdi
jmp    1210 <main+0x90>
mov    0x10(%rbx),%rsi
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rbx),%rdi
call   1070 <makeCall@plt>
test   %eax,%eax
jne    1226 <main+0xa6>
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <closePhone@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <closePhone@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"Invalid number of arguments: %d\0A\00"
@.str.1 = [6 x i8] c"telit\00"
@.str.2 = [34 x i8] c"Cannot open device for the phone\0A\00"
@.str.3 = [23 x i8] c"Cannot activate phone\0A\00"
@.str.4 = [23 x i8] c"Placing a call to: %s\0A\00"
@.str.5 = [18 x i8] c"Jenny's not home\0A\00"
@.str.6 = [16 x i8] c"Jenny is home!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 3
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @usage(i8* %11)
%13 = load i32, i32* %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @openPhone(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %16
%26 = call i32 (...) @activatePhone()
%27 = icmp ne i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 (...) @closePhone()
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %25
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @makeCall(i8* %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 (...) @closePhone()
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%48 = call i32 (...) @closePhone()
%49 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [33 x i8] c"Invalid number of arguments: %d\0A\00"
@.str.1 = [6 x i8] c"telit\00"
@.str.4 = [23 x i8] c"Placing a call to: %s\0A\00"
@str = [33 x i8] c"Cannot open device for the phone\00"
@str.7 = [22 x i8] c"Cannot activate phone\00"
@str.8 = [17 x i8] c"Jenny's not home\00"
@str.9 = [15 x i8] c"Jenny is home!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @openPhone(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %9
%18 = tail call i32 (...) @activatePhone()
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
%22 = tail call i32 (...) @closePhone()
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %17
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %25
%29 = tail call i32 @makeCall(i8* %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%33 = tail call i32 (...) @closePhone()
%34 = tail call i32 @exit(i32 -1)
unreachable
35: ; preds = %24
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.9, i64 0, i64 0))
%37 = tail call i32 (...) @closePhone()
%38 = tail call i32 @exit(i32 0)
unreachable
}