#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*/ addition(char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
void negate(char *a, char *n) {
  char a_copy[5 + 1];
  for (int i = 0; i < 5 + 1; i++)
    a_copy[i] = a[i];
  if (!strcmp(a, "10000")) {
    fprintf(stderr, "Positive overflow\n");
    exit(2);
  } else {
    for (int i = 0; i < 5; i++)
      switch (a_copy[i]) {
      case '1':
        a_copy[i] = '0';
        break;
      case '0':
        a_copy[i] = '1';
        break;
      }
    char u[5 + 1] = "00001";
    addition(a_copy, u, n);
  }
}


x86 assembly (clang, -O0):
<negate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x6,-0x1c(%rbp)
jge    1182 <negate+0x42>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x1c(%rbp),%rax
mov    %cl,-0x16(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <negate+0x17>
mov    -0x8(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11ba <negate+0x7a>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x5,-0x20(%rbp)
jge    1220 <negate+0xe0>
movslq -0x20(%rbp),%rax
movsbl -0x16(%rbp,%rax,1),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x30,%eax
je     1204 <negate+0xc4>
jmp    11e5 <negate+0xa5>
mov    -0x2c(%rbp),%eax
sub    $0x31,%eax
jne    120d <negate+0xcd>
jmp    11f6 <negate+0xb6>
movslq -0x20(%rbp),%rax
movb   $0x30,-0x16(%rbp,%rax,1)
jmp    120d <negate+0xcd>
movslq -0x20(%rbp),%rax
movb   $0x31,-0x16(%rbp,%rax,1)
jmp    1212 <negate+0xd2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c1 <negate+0x81>
mov    0xdf3(%rip),%eax
mov    %eax,-0x26(%rbp)
mov    0xded(%rip),%ax
mov    %ax,-0x22(%rbp)
lea    -0x16(%rbp),%rdi
lea    -0x26(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <addition@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<negate>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movzwl 0x4(%rdi),%eax
mov    %ax,0x4(%rsp)
mov    (%rdi),%eax
mov    %eax,(%rsp)
lea    0xea3(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     120b <negate+0xcb>
movsbl (%rsp),%eax
cmp    $0x30,%eax
je     117e <negate+0x3e>
cmp    $0x31,%eax
jne    1182 <negate+0x42>
movb   $0x30,(%rsp)
jmp    1182 <negate+0x42>
movb   $0x31,(%rsp)
movsbl 0x1(%rsp),%eax
cmp    $0x30,%eax
je     1195 <negate+0x55>
cmp    $0x31,%eax
jne    119b <negate+0x5b>
mov    $0x30,%al
jmp    1197 <negate+0x57>
mov    $0x31,%al
mov    %al,0x1(%rsp)
movsbl 0x2(%rsp),%eax
cmp    $0x30,%eax
je     11ae <negate+0x6e>
cmp    $0x31,%eax
jne    11b4 <negate+0x74>
mov    $0x30,%al
jmp    11b0 <negate+0x70>
mov    $0x31,%al
mov    %al,0x2(%rsp)
movsbl 0x3(%rsp),%eax
cmp    $0x30,%eax
je     11c7 <negate+0x87>
cmp    $0x31,%eax
jne    11cd <negate+0x8d>
mov    $0x30,%al
jmp    11c9 <negate+0x89>
mov    $0x31,%al
mov    %al,0x3(%rsp)
movsbl 0x4(%rsp),%eax
cmp    $0x30,%eax
je     11e0 <negate+0xa0>
cmp    $0x31,%eax
jne    11e6 <negate+0xa6>
mov    $0x30,%al
jmp    11e2 <negate+0xa2>
mov    $0x31,%al
mov    %al,0x4(%rsp)
movw   $0x31,0xc(%rsp)
movl   $0x30303030,0x8(%rsp)
30
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rbx,%rdx
call   1030 <addition@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"10000\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Positive overflow\0A\00"
@__const.negate.u = [6 x i8] c"00001\00"
define void @negate(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [6 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca [6 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
br label %9
9: ; preds = %21, %2
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 6
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = load i8*, i8** %3
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 %19
store i8 %17, i8* %20
br label %21
21: ; preds = %12
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %9
24: ; preds = %9
%25 = load i8*, i8** %3
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 2)
unreachable
32: ; preds = %24
store i32 0, i32* %7
br label %33
33: ; preds = %51, %32
%34 = load i32, i32* %7
%35 = icmp slt i32 %34, 5
br i1 %35, label %36, label %54
36: ; preds = %33
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
switch i32 %41, label %50 [
i32 49, label %42
i32 48, label %46
]
42: ; preds = %36
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 %44
store i8 48, i8* %45
br label %50
46: ; preds = %36
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 %48
store i8 49, i8* %49
br label %50
50: ; preds = %36, %46, %42
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %33
54: ; preds = %33
%55 = bitcast [6 x i8]* %8 to i8*
%56 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%57 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%58 = load i8*, i8** %4
%59 = call i32 @addition(i8* %56, i8* %57, i8* %58)
br label %60
60: ; preds = %54
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"10000\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Positive overflow\0A\00"
@__const.negate.u = [6 x i8] c"00001\00"
define void @negate(i8* nocapture %0, i8* %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%5 = alloca [6 x i8]
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8, i8* %6
%11 = sext i8 %10 to i32
switch i32 %11, label %18 [
i32 49, label %16
i32 48, label %17
]
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %9
store i8 48, i8* %6
br label %18
17: ; preds = %9
store i8 49, i8* %6
br label %18
18: ; preds = %16, %17, %9
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %25 [
i32 49, label %22
i32 48, label %23
]
22: ; preds = %18
br label %23
23: ; preds = %18, %22
%24 = phi i8 [ 48, %22 ], [ 49, %18 ]
store i8 %24, i8* %19
br label %25
25: ; preds = %23, %18
%26 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 2
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
switch i32 %28, label %32 [
i32 49, label %29
i32 48, label %30
]
29: ; preds = %25
br label %30
30: ; preds = %25, %29
%31 = phi i8 [ 48, %29 ], [ 49, %25 ]
store i8 %31, i8* %26
br label %32
32: ; preds = %30, %25
%33 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 3
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
switch i32 %35, label %39 [
i32 49, label %36
i32 48, label %37
]
36: ; preds = %32
br label %37
37: ; preds = %32, %36
%38 = phi i8 [ 48, %36 ], [ 49, %32 ]
store i8 %38, i8* %33
br label %39
39: ; preds = %37, %32
%40 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 4
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
switch i32 %42, label %46 [
i32 49, label %43
i32 48, label %44
]
43: ; preds = %39
br label %44
44: ; preds = %39, %43
%45 = phi i8 [ 48, %43 ], [ 49, %39 ]
store i8 %45, i8* %40
br label %46
46: ; preds = %44, %39
%47 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%48 = call i32 @addition(i8* %6, i8* %47, i8* %1)
ret void
}