#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 */
scalar_t__ _rpi_nano_exit_AT(int);
int _rpi_nano_get_reg(int, char *, int *);
scalar_t__ _rpi_nano_switch_to_AT(int);
int rpi_nano_get_modem_address(int fd) {
  int err = -1;
  if (_rpi_nano_switch_to_AT(fd))
    return -1;
  int val = -1;
  err = _rpi_nano_get_reg(fd, "S097", &val);
  if (_rpi_nano_exit_AT(fd))
    return -1;
  return err ? -1 : val;
}


x86 assembly (clang, -O0):
<rpi_nano_get_modem_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <_rpi_nano_switch_to_AT@plt>
cmp    $0x0,%rax
je     1160 <rpi_nano_get_modem_address+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <rpi_nano_get_modem_address+0x8e>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe8f(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <_rpi_nano_get_reg@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <_rpi_nano_exit_AT@plt>
cmp    $0x0,%rax
je     119b <rpi_nano_get_modem_address+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <rpi_nano_get_modem_address+0x8e>
cmpl   $0x0,-0xc(%rbp)
je     11b2 <rpi_nano_get_modem_address+0x82>
mov    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <rpi_nano_get_modem_address+0x88>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpi_nano_get_modem_address>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1030 <_rpi_nano_switch_to_AT@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    117a <rpi_nano_get_modem_address+0x4a>
movl   $0xffffffff,0x4(%rsp)
ff
lea    0xeaa(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1040 <_rpi_nano_get_reg@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <_rpi_nano_exit_AT@plt>
neg    %ebp
sbb    %ecx,%ecx
or     0x4(%rsp),%ecx
neg    %rax
sbb    %eax,%eax
or     %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"S097\00"
define i32 @rpi_nano_get_modem_address(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 -1, i32* %4
%6 = load i32, i32* %3
%7 = call i64 @_rpi_nano_switch_to_AT(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %25
10: ; preds = %1
store i32 -1, i32* %5
%11 = load i32, i32* %3
%12 = call i32 @_rpi_nano_get_reg(i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %5)
store i32 %12, i32* %4
%13 = load i32, i32* %3
%14 = call i64 @_rpi_nano_exit_AT(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 -1, i32* %2
br label %25
17: ; preds = %10
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
br label %23
21: ; preds = %17
%22 = load i32, i32* %5
br label %23
23: ; preds = %21, %20
%24 = phi i32 [ -1, %20 ], [ %22, %21 ]
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %16, %9
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [5 x i8] c"S097\00"
define i32 @rpi_nano_get_modem_address(i32 %0) {
%2 = alloca i32
%3 = tail call i64 @_rpi_nano_switch_to_AT(i32 %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%7 = call i32 @_rpi_nano_get_reg(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = call i64 @_rpi_nano_exit_AT(i32 %0)
%9 = icmp eq i64 %8, 0
%10 = icmp eq i32 %7, 0
%11 = load i32, i32* %2
%12 = select i1 %9, i1 %10, i1 false
%13 = select i1 %12, i32 %11, i32 -1
br label %14
14: ; preds = %1, %5
%15 = phi i32 [ %13, %5 ], [ -1, %1 ]
ret i32 %15
}