#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*/ printf(char *);
scalar_t__ send_modem_command(int, char *);
int /*<<< orphan*/ sleep(int);
int init_modem(int fd) {
  printf("sending ATZ command...\n");
  if (send_modem_command(fd, "ATZ\r") != 0) {
    return (-1);
  }
  sleep(1);
  printf("sending caller ID command...\n");
  if (send_modem_command(fd, "AT+VCID=1\r") != 0) {
    return (-1);
  }
  printf("sending FAX mode command...\n");
  send_modem_command(fd, "AT+FCLASS=2\r");
  return (0);
}


x86 assembly (clang, -O0):
<init_modem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xec7(%rip),%rsi
call   1040 <send_modem_command@plt>
cmp    $0x0,%rax
je     116c <init_modem+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <init_modem+0x99>
mov    $0x1,%edi
call   1050 <sleep@plt>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xeaf(%rip),%rsi
call   1040 <send_modem_command@plt>
cmp    $0x0,%rax
je     11a7 <init_modem+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <init_modem+0x99>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xea6(%rip),%rsi
call   1040 <send_modem_command@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_modem>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rsi
mov    %ebx,%edi
call   1040 <send_modem_command@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    119e <init_modem+0x6e>
mov    $0x1,%edi
call   1050 <sleep@plt>
lea    0xeca(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8f(%rip),%rsi
mov    %ebx,%edi
call   1040 <send_modem_command@plt>
test   %rax,%rax
jne    119e <init_modem+0x6e>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7b(%rip),%rsi
mov    %ebx,%edi
call   1040 <send_modem_command@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"sending ATZ command...\0A\00"
@.str.1 = [5 x i8] c"ATZ\0D\00"
@.str.2 = [30 x i8] c"sending caller ID command...\0A\00"
@.str.3 = [11 x i8] c"AT+VCID=1\0D\00"
@.str.4 = [29 x i8] c"sending FAX mode command...\0A\00"
@.str.5 = [13 x i8] c"AT+FCLASS=2\0D\00"
define i32 @init_modem(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* %3
%6 = call i64 @send_modem_command(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %20
9: ; preds = %1
%10 = call i32 @sleep(i32 1)
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* %3
%13 = call i64 @send_modem_command(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 -1, i32* %2
br label %20
16: ; preds = %9
%17 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%18 = load i32, i32* %3
%19 = call i64 @send_modem_command(i32 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %2
br label %20
20: ; preds = %16, %15, %8
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"ATZ\0D\00"
@.str.3 = [11 x i8] c"AT+VCID=1\0D\00"
@.str.5 = [13 x i8] c"AT+FCLASS=2\0D\00"
@str = [23 x i8] c"sending ATZ command...\00"
@str.6 = [29 x i8] c"sending caller ID command...\00"
@str.7 = [28 x i8] c"sending FAX mode command...\00"
define i32 @init_modem(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%3 = tail call i64 @send_modem_command(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.6, i64 0, i64 0))
%8 = tail call i64 @send_modem_command(i32 %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0))
%12 = tail call i64 @send_modem_command(i32 %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %13
13: ; preds = %5, %1, %10
%14 = phi i32 [ 0, %10 ], [ -1, %1 ], [ -1, %5 ]
ret i32 %14
}