#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("Init modem: (ATZ)  ");
  if (send_modem_command(fd, "ATZ\r") != 0) {
    return (-1);
  }
  sleep(1);
  printf("(CID)  ");
  if (send_modem_command(fd, "AT+VCID=1\r") != 0) {
    return (-1);
  }
  printf("(FAX)\n");
  send_modem_command(fd, "AT+FCLASS=1\r");
  printf("Waiting for a call...\n\n");
  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    0xec3(%rip),%rsi
call   1040 <send_modem_command@plt>
cmp    $0x0,%rax
je     116c <init_modem+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <init_modem+0xa5>
mov    $0x1,%edi
call   1050 <sleep@plt>
lea    0xe9c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe95(%rip),%rsi
call   1040 <send_modem_command@plt>
cmp    $0x0,%rax
je     11a7 <init_modem+0x77>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <init_modem+0xa5>
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe76(%rip),%rsi
call   1040 <send_modem_command@plt>
lea    0xe77(%rip),%rdi
call   1030 <printf@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    0xeb4(%rip),%rdi
call   1040 <printf@plt>
lea    0xebc(%rip),%rsi
mov    %ebx,%edi
call   1050 <send_modem_command@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
jne    11ba <init_modem+0x7a>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9b(%rip),%rsi
mov    %ebx,%edi
call   1050 <send_modem_command@plt>
test   %rax,%rax
jne    11ba <init_modem+0x7a>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
lea    0xe87(%rip),%rsi
mov    %ebx,%edi
call   1050 <send_modem_command@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Init modem: (ATZ) \00"
@.str.1 = [5 x i8] c"ATZ\0D\00"
@.str.2 = [8 x i8] c"(CID) \00"
@.str.3 = [11 x i8] c"AT+VCID=1\0D\00"
@.str.4 = [7 x i8] c"(FAX)\0A\00"
@.str.5 = [13 x i8] c"AT+FCLASS=1\0D\00"
@.str.6 = [24 x i8] c"Waiting for a call...\0A\0A\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 ([20 x i8], [20 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 %21
9: ; preds = %1
%10 = call i32 @sleep(i32 1)
%11 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 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 %21
16: ; preds = %9
%17 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 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))
%20 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %2
br label %21
21: ; preds = %16, %15, %8
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [20 x i8] c"Init modem: (ATZ) \00"
@.str.1 = [5 x i8] c"ATZ\0D\00"
@.str.2 = [8 x i8] c"(CID) \00"
@.str.3 = [11 x i8] c"AT+VCID=1\0D\00"
@.str.5 = [13 x i8] c"AT+FCLASS=1\0D\00"
@str = [6 x i8] c"(FAX)\00"
@str.7 = [23 x i8] c"Waiting for a call...\0A\00"
define i32 @init_modem(i32 %0) {
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 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 %14
5: ; preds = %1
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, 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 %14
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, 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))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
br label %14
14: ; preds = %5, %1, %10
%15 = phi i32 [ 0, %10 ], [ -1, %1 ], [ -1, %5 ]
ret i32 %15
}