#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 */
typedef int /*<<< orphan*/ reply;
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
void send_at_cmgf(int fd, char *c) {
  int nread, nwrite;
  char buff[128];
  char reply[128];
  memset(buff, 0, sizeof(buff));
  strcpy(buff, "AT+CMGF=");
  strcat(buff, c);
  strcat(buff, "\r");
  nwrite = write(fd, buff, strlen(buff));
  memset(reply, 0, sizeof(reply));
  sleep(1);
  nread = read(fd, reply, sizeof(reply));
}


x86 assembly (clang, -O0):
<send_at_cmgf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x12c(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x12c(%rbp),%edi
mov    -0x128(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x80,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_at_cmgf>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
lea    0x80(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe61(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <strcat@plt>
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1070 <read@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"AT+CMGF=\00"
@.str.1 = [2 x i8] c"\0D\00"
define void @send_at_cmgf(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca [128 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 0, i32 128)
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = call i32 @strcat(i8* %13, i8* %14)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%17 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %3
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
store i32 %22, i32* %6
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%24 = call i32 @memset(i8* %23, i32 0, i32 128)
%25 = call i32 @sleep(i32 1)
%26 = load i32, i32* %3
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 128)
store i32 %28, i32* %5
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"AT+CMGF=\00"
@.str.1 = [2 x i8] c"\0D\00"
define void @send_at_cmgf(i32 %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %5, i32 0, i32 128)
%8 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @strcat(i8* %5, i8* %1)
%10 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @strlen(i8* %5)
%12 = call i32 @write(i32 %0, i8* %5, i32 %11)
%13 = call i32 @memset(i8* %6, i32 0, i32 128)
%14 = call i32 @sleep(i32 1)
%15 = call i32 @read(i32 %0, i8* %6, i32 128)
ret void
}