#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 /*<<< orphan*/ printf(char *, int, char *);
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_cmgs(int fd, char *cmgs, char *message) {
  int nread, nwrite;
  char buff[20000];
  char reply[20000];
  memset(buff, 0, sizeof(buff));
  strcpy(buff, "AT+CMGS=");
  strcat(buff, cmgs);
  strcat(buff, "\r");
  nwrite = write(fd, buff, strlen(buff));
  memset(reply, 0, sizeof(reply));
  sleep(1);
  nread = read(fd, reply, sizeof(reply));
  memset(buff, 0, sizeof(buff));
  strcpy(buff, message);
  nwrite = write(fd, buff, strlen(buff));
  memset(reply, 0, sizeof(reply));
  sleep(1);
  nread = read(fd, reply, sizeof(reply));
  printf("nread=%d,%s\n", nread, reply);
}


x86 assembly (clang, -O0):
<send_at_cmgs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x4e40(%rbp),%rdi
xor    %esi,%esi
mov    $0x4e20,%edx
call   1070 <memset@plt>
lea    -0x4e40(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x4e40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x4e40(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x9c7c(%rbp)
lea    -0x4e40(%rbp),%rax
mov    %rax,-0x9c78(%rbp)
lea    -0x4e40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x9c7c(%rbp),%edi
mov    -0x9c78(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x20(%rbp)
lea    -0x9c60(%rbp),%rdi
xor    %esi,%esi
mov    $0x4e20,%edx
call   1070 <memset@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x4(%rbp),%edi
lea    -0x9c60(%rbp),%rsi
mov    $0x4e20,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x4e40(%rbp),%rdi
xor    %esi,%esi
mov    $0x4e20,%edx
call   1070 <memset@plt>
lea    -0x4e40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x9c6c(%rbp)
lea    -0x4e40(%rbp),%rax
mov    %rax,-0x9c68(%rbp)
lea    -0x4e40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x9c6c(%rbp),%edi
mov    -0x9c68(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x20(%rbp)
lea    -0x9c60(%rbp),%rdi
xor    %esi,%esi
mov    $0x4e20,%edx
call   1070 <memset@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x4(%rbp),%edi
lea    -0x9c60(%rbp),%rsi
mov    $0x4e20,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    -0x9c60(%rbp),%rdx
lea    0xd1c(%rip),%rdi
call   1060 <printf@plt>
add    $0x9c80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_at_cmgs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x9c40,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %edi,%r12d
lea    0x4e20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4e20,%edx
call   1070 <memset@plt>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strcat@plt>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4e20,%edx
call   1070 <memset@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x4e20,%edx
call   1080 <read@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4e20,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4e20,%edx
call   1070 <memset@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x4e20,%edx
call   1080 <read@plt>
lea    0xd93(%rip),%rdi
mov    %eax,%esi
mov    %r15,%rdx
call   1060 <printf@plt>
add    $0x9c40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"AT+CMGS=\00"
@.str.1 = [2 x i8] c"\0D\00"
@.str.2 = [13 x i8] c"nread=%d,%s\0A\00"
define void @send_at_cmgs(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [20000 x i8]
%10 = alloca [20000 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 20000)
%13 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %5
%17 = call i32 @strcat(i8* %15, i8* %16)
%18 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* %4
%21 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%22 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @write(i32 %20, i8* %21, i32 %23)
store i32 %24, i32* %8
%25 = getelementptr inbounds [20000 x i8], [20000 x i8]* %10, i64 0, i64 0
%26 = call i32 @memset(i8* %25, i32 0, i32 20000)
%27 = call i32 @sleep(i32 1)
%28 = load i32, i32* %4
%29 = getelementptr inbounds [20000 x i8], [20000 x i8]* %10, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 20000)
store i32 %30, i32* %7
%31 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%32 = call i32 @memset(i8* %31, i32 0, i32 20000)
%33 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%34 = load i8*, i8** %6
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = load i32, i32* %4
%37 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%38 = getelementptr inbounds [20000 x i8], [20000 x i8]* %9, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @write(i32 %36, i8* %37, i32 %39)
store i32 %40, i32* %8
%41 = getelementptr inbounds [20000 x i8], [20000 x i8]* %10, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 20000)
%43 = call i32 @sleep(i32 1)
%44 = load i32, i32* %4
%45 = getelementptr inbounds [20000 x i8], [20000 x i8]* %10, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 20000)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = getelementptr inbounds [20000 x i8], [20000 x i8]* %10, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %47, i8* %48)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"AT+CMGS=\00"
@.str.1 = [2 x i8] c"\0D\00"
@.str.2 = [13 x i8] c"nread=%d,%s\0A\00"
define void @send_at_cmgs(i32 %0, i8* %1, i8* %2) {
%4 = alloca [20000 x i8]
%5 = alloca [20000 x i8]
%6 = getelementptr inbounds [20000 x i8], [20000 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [20000 x i8], [20000 x i8]* %5, i64 0, i64 0
%8 = call i32 @memset(i8* %6, i32 0, i32 20000)
%9 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @strcat(i8* %6, i8* %1)
%11 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @strlen(i8* %6)
%13 = call i32 @write(i32 %0, i8* %6, i32 %12)
%14 = call i32 @memset(i8* %7, i32 0, i32 20000)
%15 = call i32 @sleep(i32 1)
%16 = call i32 @read(i32 %0, i8* %7, i32 20000)
%17 = call i32 @memset(i8* %6, i32 0, i32 20000)
%18 = call i32 @strcpy(i8* %6, i8* %2)
%19 = call i32 @strlen(i8* %6)
%20 = call i32 @write(i32 %0, i8* %6, i32 %19)
%21 = call i32 @memset(i8* %7, i32 0, i32 20000)
%22 = call i32 @sleep(i32 1)
%23 = call i32 @read(i32 %0, i8* %7, i32 20000)
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %23, i8* %7)
ret void
}